refaktor / rye

homoiconic dynamic programming language with some new ideas
https://ryelang.org
Apache License 2.0
406 stars 21 forks source link

autotype panics with non-string column #290

Closed cwarden closed 1 month ago

cwarden commented 1 month ago

Calling autotype on a spreadsheet with non-string columns panics:

$ rye -do 'spreadsheet { "name" "value" } [ "Joe" 523343434.0000 ] |autotype 0.95'
panic: interface conversion: interface {} is env.Decimal, not env.String

goroutine 1 [running]:
github.com/refaktor/rye/evaldo.AutoType(0x0?, 0xc000275598, 0x3fee666666666666)
        /home/cwarden/git/rye/evaldo/builtins_spreadsheet.go:1137 +0x805
github.com/refaktor/rye/evaldo.init.func390(0x0?, {0x95c5b0?, 0xc0002e1c80?}, {0x95c6a0?, 0xc0000144b8?}, {0x0?, 0x0?}, {0x0?, 0x0?}, {0x0, ...})
        /home/cwarden/git/rye/evaldo/builtins_spreadsheet.go:710 +0xb4
github.com/refaktor/rye/evaldo.CallBuiltin({0x8dbcc8, 0x2, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, {0x0, 0x0}, ...}, ...)
        /home/cwarden/git/rye/evaldo/evaldo.go:1011 +0xcc3
github.com/refaktor/rye/evaldo.EvalObject(0xc0000bb790, {0x95cb50, 0xc000255700}, {0x95c5b0, 0xc0002e1c80}, 0x0, 0x0, 0x0, {0x0, 0x0})
        /home/cwarden/git/rye/evaldo/evaldo.go:531 +0x190
github.com/refaktor/rye/evaldo.EvalWord(0xc0000bb790, {0x95c510, 0xc0000144d0}, {0x95c5b0, 0xc0002e1c80}, 0x0, 0x0)
        /home/cwarden/git/rye/evaldo/evaldo.go:476 +0x3a6
github.com/refaktor/rye/evaldo.MaybeEvalOpwordOnRight({0x95cd80?, 0xc0000144c0?}, 0xc0000bb790, 0x0)
        /home/cwarden/git/rye/evaldo/evaldo.go:285 +0x605
github.com/refaktor/rye/evaldo.EvalExpressionInj(0xc0000bb790?, {0x0?, 0x0?}, 0x0)
        /home/cwarden/git/rye/evaldo/evaldo.go:196 +0xb2
github.com/refaktor/rye/evaldo.EvalBlockInj(0xc000038140?, {0x0, 0x0}, 0x90?)
        /home/cwarden/git/rye/evaldo/evaldo.go:81 +0x4f
github.com/refaktor/rye/evaldo.EvalBlock(...)
        /home/cwarden/git/rye/evaldo/evaldo.go:49
github.com/refaktor/rye/runner.main_rye_file({0x0, 0x0}, 0x0, 0x1, 0x0, {0x7ffce14e4952, 0x46}, 0x8daf30)
        /home/cwarden/git/rye/runner/runner.go:388 +0x54e
github.com/refaktor/rye/runner.DoMain(0x8daf30)
        /home/cwarden/git/rye/runner/runner.go:112 +0x2b5
main.main()
        /home/cwarden/git/rye/main.go:36 +0x1a
refaktor commented 1 month ago

Thank you for finding this. Autotype was used to get types to spreasheet that was loaded from csv, where all columns were text (before autotype). But you are correct, it should work sensibly also in other cases (and never panic). It's fixed in https://github.com/refaktor/rye/pull/291

Thanks!