Open krame505 opened 5 years ago
Perhaps do the third option now and leave this issue open until we can do option 2?
Just tried implementing option 3, turns out this doesn't quite work. All variables captured by an anonymous class (as used in lambdas and pattern matching) must be effectively final, so that rules out setting it to null and mutating the variable later when it is initialized.
A slightly less invasive solution than 2, rather than modifying the existing environment, might be to add a secondary environment for action blocks that "flows down" in the expected way, purely for tracking what locals have been initialized so far.
Currently locals in Copper action blocks share the same environment handling as production bodies, since action blocks are really production bodies in disguise. This means that we can reference them before they are defined (since production bodies are one big let-rec), but the translation works differently than for a production, generating non-compilable code that references uninitialized variables. I can think of a few possible solutions for this:
null
, raise an error at runtime when referencing an uninitialized local. This is what I did to fix parser attributes in #301, and would be a fairly quick fix.Thoughts?