potion
potion copied to clipboard
`to` segfaults when using a variable as the upper bound
Things work fine when using a variable as the lower bound, but Potion seems to segfault when using one as the upper bound. Example:
>> n = 3, n to 5 (i): i string print.
345=> 3
>> n = 5, 3 to n (i): i string print.
[1] 79643 segmentation fault ./potion
Am I missing something?
This is one of many subtle issues with this program. You are not missing something.
Thanks for reporting, and feel free to fix it :).
The current workaround is to use parens for the to method call:
n = 5, 3 to (n, (i): i string print.) # => 345
I'll try to fix this special case in the compiler, so that the parens are optional.
The following seems to work as well:
n = 5, 3 to (n) (i): i string print. # => 345
The issue is that literal values are treated differently than names, which could be a variable or another method call.
For instance in the code
up = 2, self add up
Would be ambiguous between calling add on self with no arguments, then calling up on the result, and calling add on self with a parameter up. There is no way to fix this without making the parentheses required, or making the grammar context sensitive (i.e. checking to see if each message is a variable in the current context before deciding how to treat it.
As @rurban says, this could be special cased (just for the to method on Number), but this would only work on literals.
n = 3, m = 5, n to m (i): i string print.
could not be special cased in this way, as we currently can't decide if n is a number.
It would also prevent the use of to being used in a different manner for another object.