pyret-lang icon indicating copy to clipboard operation
pyret-lang copied to clipboard

Not great error for using `x` for multiplication.

Open dbp opened this issue 6 months ago • 5 comments

If I write:

5 x 10

I get the following error:

Image

I wonder if there is a way to trigger unbound identifier errors first? I'm not sure if that's the right way to improve this, but it at least feels like it would be better to see something like:

Image

dbp avatar Jul 01 '25 21:07 dbp

We really ought to be able to notice this case of multiple expressions on the same line that overlap with an x in the middle. The issue is with the literal id x, which requires no special scope resolution, etc.

jpolitz avatar Jul 01 '25 23:07 jpolitz

Oh that's an interesting ergonomic issue, and I'm kinda impressed we haven't encountered it before... I think we could handle that using the pattern Joe suggested above, though I'm slightly worried about false-positives: I can easily believe that a student writing 5 x 10 meant for multiplication, because of the two integer literals, but should something like w x y z trigger a "x isn't multiplication" warning?

blerner avatar Jul 02 '25 16:07 blerner

While obviously there are more complicated math expressions that it wouldn't catch, I feel like this is most likely to occur at first, and so it might be "good enough" to recognize NUM x NUM, rather than EXPR x EXPR (or even more general, as your example @blerner).

dbp avatar Jul 02 '25 18:07 dbp

Could be. I don't like the thought of hard-coding such a brittle warning pattern, but it may be worth it...

blerner avatar Jul 02 '25 19:07 blerner

There's already an issue where we report 2 different errors for one line with 3 expressions. (In general for e1 e2 e3... en we report $$n-1$$ errors). It would be good to clean that up in general, and in doing so we collapse adjacent errors if the shared expression is x

jpolitz avatar Jul 02 '25 20:07 jpolitz