Open
Description
Some Scratch 2.0 projects have blocks that reference variables that are not declared anywhere in the project.
E.g. The projects referenced in the following issues:
scratchfoundation/scratch-gui#2180
scratchfoundation/scratch-gui#2094
Importing these projects into 3.0 causes variable conflicts such that a variable with the same name and type can be referring to different IDs in the same scope.
Make the VM state consistent by resolving these conflicts and correcting the referencing fields when the project is imported:
Solution:
- When there are blocks referencing undeclared variables, create a local variable when possible (e.g. when the block is on a sprite, and the stage also didn't have a block referencing a variable with the same name and type).
- If the block referencing an undeclared variable is on the stage, create a global variable.
- If there are blocks on other sprites referencing an undeclared variable of the same name and type, merge those variable references with the newly created global variable.
- If there is a sprite with an actual declared local variable with the same name and type as the undeclared variable reference on the type, the new global variable should be created with a new name that doesn't have conflicts with any declared local variables.
Repro
- Create a local variable in a scratch 2 sprite
- Share the reporter block to the stage
- Do not run the block
- Save the project and open in 3.0