-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logic_compare: Type-verification creates top level shadow block as a side effect #1408
Comments
Oooh. Neat bug! The fact that the shadow gets bumped onto the workspace is definitely a problem. Beyond that part, this is tricky. When you say you expect the text block to be bumped, do you mean it should never have connected in the first place? What types do you want to be able to compare using the == block? Do you want to be able to compare a number and a string and use a cast in the generator? I suspect the == block in the playground doesn't have shadows at all to avoid dealing with the complexity of switching types like this :) |
Yeah I don't think there's any issue with the connecting logic. The bug is just that it bumps the shadow out onto the workspace. Although I do agree, it would be nice to have a union type for the equality block since you should be able to compare two strings, or a string and a number (false?), but that's a different story. (And perhaps this isn't a Blockly thing, and can be solved by having a union (string | number) block). |
Actually, this (awesome) bug exists because it never occurred to me to test the intersection of =='s custom connection logic and shadow blocks. :) I'd vote to refuse connect a non-compatible block if the conflicting block is a shadow or unmovable. After all, if the developer places a shadow block in a == block, then I feel they have strongly defined the type. This bug may also affect the ?: ternary block as well. |
Neil's solution implies the toolbox would need to either remove shadow blocks, or have a comparison operator for every type (number, string, list, etc). This toolbox change is going to affect anyone who has copied a demo toolbox since we introduced shadows. If we implement Neil's suggestion, and a developer does not update their toolbox shadows, their users will not be able to compare strings. A more compatible approach would be to delete the shadow if it is incompatible. A more user-friendly variant (but much more complicated) might replace include special handling of the In this case, for other unrecognized types we could implement either shadow deletion or connection invalidation. In terms of the demo toolboxes, the separation of number comparisons and string comparisons makes me feel the blocks belong in the Math and Text categories, instead of the logic category. (Or remove the shadows, as I previously mentioned.) |
Correction. Blockly toolbox does not (and presumably has not) used shadows in |
* Create prevBlock_ upon first call to onchange. * Revert state upon an incompatible combination, bumping the new incompatible block, instead of the old block. Thus, the shadow is never the bumped block. Bug: * The undo stack get caught in a loop, and will never undo back to a state equivalent to the previous action.
Rewrote LOGIC_COMPARE_ONCHANGE_MIXIN to fix #1408.
why you did not support |
Problem statement
Dragging a block that's an incompatible type bumps the block and then creates a top level shadow block as a sideeffect.
Expected Behavior
The text block should be bumped, with no new (top level) shadow block created.
Actual Behavior
The text block is bumped and a new (top level) shadow block appears in the workspace. This is consistent, and happens for every bump.
Also happens when inserting a Color block into a Number field, but doesn't happen when inserting a number block into a String field.
Steps to Reproduce
Take this block XML and try to insert a text block inside of the LHS of the number comparator.
Stack Traces
Here's the generated XML as a result of this:
Operating System and Browser
Affects both develop and master
The text was updated successfully, but these errors were encountered: