[Google Blockly] Fix custom getVars implementations#60459
Merged
Conversation
molly-moen
approved these changes
Aug 15, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A couple issues came up during the Artist bug bash that shared a root cause related to the
block.getVarsmethod.At the Artist Binary level

/s/course4/lessons/18/levels/9?blocklyVersion=google, an error is displayed saying that we can't run the code:This happens as part of a check to make sure nested for loops don't use the same variable.
This branch is based on #60448 because I also noticed that the
controls_for_counterblock was affected.Explanation
Google Blockly has a standard implementation of
block.getVars()that returns a list of variable names:https://github.com/google/blockly/blob/17e4f1c96665dd56ff33f5a45db809f7e2805e82/core/block.ts#L1118-L1134
In CDO Blockly however, the same function returned an object with keys (representing variable types) and values (list of variable names of the given type). This explains the previous version of each version of
getVars()that was modified in this branch. Most of these are old. In the case of migrated labs like Sprite Lab and Dance, we don't see to ever actually need or call these functions.The outlier here is the implementation for
Blockly.Variables.getVarswhich was added before Sprite Lab was migrated here:https://github.com/code-dot-org/code-dot-org/pull/55276/files#diff-ff941d5d2ca36511c7401a50c5160671b0bba06e9bbd8f0d34ef21128e8a4f0bR22-R31
This was part of an effort to pre-emptively import missing variable methods from CDO Blockly. Unfortunately, that version wouldn't have worked as expected because it had the wrong return type for Google Blockly. Several functions in that PR (#55276) weren't able to be manually tested; we were just hoping that importing the CDO definitions would be helpful down the road.
After uncovering this descrepency, I was able to rework
Blockly.Variables.getVarsto just return a simple list of variable names. This function is assigned to several Artist blocks asblock.getVars:variables_get_counter,variables_get_length,variables_get_sides, andcontrols_for_counter, all of which should now be working.I did the same for several other custom
getVarsimplementations, namely those used by blocks defined in our pools. These blocks are just found in Sprite Lab and Dance. Again, there doesn't seem to be any evidence that we've actually needed the block method in these labs which is why it hasn't been a problem. However, it makes sense to make them work correctly, should we need them in the future.As a similar point of clean up, I noticed we also provided a custom
getVarsas part of thelocationVariableDropdowncustom input type. This was an experimental idea for a type of Sprite Lab block that would have worked with location variables (thinkvar top = {x: 200, y: 400};. The idea was never fully implemented. In fact, there is no other reference tolocationVariableDropdownin our entire main repo. Therefore, instead of updating this instance ofgetVarI instead deleted the entire custom input type.Links
Bug Bash: https://docs.google.com/document/d/14nGoZMVSptvDnRt1He0t6JQBRf-Em3ZcSIMUoEPYMq0/edit
Testing story
I manually tested that previously-broken levels were now working.

It's also possible to get feedback about using nested loops with the same variable:
I confirmed that there were no regressions with blocks using the custom variable input or sprite picker in both Sprite Lab (shown) and Dance:

Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: