potion icon indicating copy to clipboard operation
potion copied to clipboard

`to` segfaults when using a variable as the upper bound

Open sjl opened this issue 13 years ago • 3 comments

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?

sjl avatar Nov 08 '11 23:11 sjl

This is one of many subtle issues with this program. You are not missing something.

Thanks for reporting, and feel free to fix it :).

ghost avatar Nov 09 '11 01:11 ghost

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.

rurban avatar Oct 04 '13 21:10 rurban

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.

robotii avatar Nov 19 '15 09:11 robotii