rascal
rascal copied to clipboard
Inconsistent type inference between code typed in the REPL and imported as module.
Describe the bug
The same set of definitions typed step-by-step in the REPL and imported as a module produce different behaviours.
To Reproduce
-
Suppose the following definitions:
data s_cell = push(int a); alias s_stack = list[s_cell]; data s_sym = push(int a)|add(); alias s_prog = list[s_sym]; -
And the following minimal "test":
for([add(), *s_cell r]:=[add(), push(0), push(0), push(0)]) print(r);
If the type definitions in (1) are typed into the REPL, then (2) works. If they are put in a module and imported then (2) does not return the same result. Specifically:
If block 1 is typed in the REPL:
This is inferred as a list[s_cell] (Expected).
[push(0), push(0)]
This is inferred as a list[node] (Kind of expected, it sees symbols from two different types, it's fine to report this as a list of the general common ancestor node)
[add(), push()]
This works (Expected)
import IO;
for ([add(), *s_cell q]:=[add(), push(0), push(0), push(0)]) print(q);
//Returns [push(0), push(0), push(0)]
If block 1 is put in a module and imported, then:
This is inferred as a list[s_sym]. (...Not expected)
[push(0), push(0)]
This is inferred as a list[s_sym] (Expected...but puzzling)
[add(), push()]
This fails (Not expected)
import IO;
for ([add(), *s_cell q]:=[add(), push(0), push(0), push(0)]) print(q);
//Returns []
Expected behavior
I think that the REPL behaviour should be the expected one.
Desktop (please complete the following information):
- Context: Commandline REPL
- Rascal Version 0.28.11
Additional context I am working along a specific example here, which is not posted in its entirety. However, the point of raising this is not this specific example but the behaviour it causes.