melt-umn / silver

An attribute grammar-based programming language for composable language extensions
http://melt.cs.umn.edu/silver/
GNU Lesser General Public License v3.0
58 stars 7 forks source link

Referencing a local in an action block before its definition generates invalid code #303

Open krame505 opened 5 years ago

krame505 commented 5 years ago

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:

Thoughts?

ericvanwyk commented 5 years ago

Perhaps do the third option now and leave this issue open until we can do option 2?

krame505 commented 5 years ago

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.