encore
encore copied to clipboard
A call from a closure to a function defined in a where clause produces wrong C code
A call from a closure to a function defined in a where
clause produces code that cannot be compiled. For instance:
class Main
def main() : unit
fun (x: int) => inc(x)
where
fun inc(x: int): int
x + 1
end
end
end
Typechecks but throws this error in C:
encorec test.enc
test_src/Main.encore.c:249:43: error: use of undeclared identifier '_enc__closure_inc'
(*_enc__env_closure0)._enc__field_inc = _enc__closure_inc;
^
1 error generated.
*** Compilation failed with exit code 1 ***
Interestingly, the following does compile:
active class Main
def main() : unit
val inc = inc
fun (x: int) => inc(x)
where
fun inc(x: int): int
x + 1
end
end
end
I would guess that the local functions aren't properly added to the environment when translating the closure.