brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

Leakage of undefined in generated cases lists on non-data values #1294

Open jpolitz opened 6 years ago

jpolitz commented 6 years ago

image

jpolitz commented 6 years ago

Relatedly (not strictly a bug according to our current arguments for the design of cases...)

image

blerner commented 6 years ago

Ugh, thanks javascript. I'm kinda amazed that neither of these first two cases crash, and that they produce contradictory descriptions in the output. It's because we're looking up 2.$name, which is undefined, and 2.$arity, which is also undefined and therefore isn't -1 (in the first case) or 1 (in the second).

We would need to check either that Number (or the annotation in general) is something derived from a data annotation, or that 5 has a non-undefined $name field -- though the first is tricky and the second would slow down every cases expression by another if test. Also, we use cases(Any) ... end in various places in the compiler, so that's slightly awkward.