CUSTOM Block parameters - local vs global discrepancy

Issue #87 resolved
Turgut Guneysu created an issue

Hi John,

I was testing the 3.4 release when I noticed the following:

  • I define a custom block with 3 parameters: foo=1, bar=22, baz=333

  • Then edit the block definition and delete the BAZ parameter from the header

So the SAY block now must refer to a non-existing local-var BAZ with garbage value 2. And at this point there is no other global var with the name BAZ.

  • I define a new global var BAZ. The executed myBlock still refers to non-existing local-var BAZ with garbage value 2 (I believe this to be wrong). The new var’s default value is 0.

  • Now I assign a value to the global var BAZ = 888. Block executions still show the old values for the custom block (I believe this to be wrong) and also the global var’s correct value.

I think the BAZ handling of the CUSTOM block is in error:

  • Once it was deleted in step 2, it’s SCOPE should have been changed to non-local.
  • At the very least, in the last step, when BAZ=888 executes, it’s SCOPE should have been changed to global.
  • Furthermore, when at the last step, the custom block’s SAY executes, it should have picked up the new context of the BAZ variable.

AND the saga continues:

  • I edit the custom block and add another parameter, it defaults to BAZ; I assign the default value 333, and microBlocks crashes !

I have tried this many many times with the same results. So it pretty reproducible.

Comments (3)

  1. John Maloney repo owner

    I fixed several bugs associated with this sequence. First, when you delete the parameter “baz” it becomes a local but the value is (correctly) initialized to zero. It’s slightly confusing because there is no “initialize local” block, but in every other way it behaves like a local variable.

    Second, when you declare a global “baz” the variable “baz” in the body of myBlock is re-bound to the global.

    Finally, it doesn’t crash if you re-add baz as a parameter. And references to baz in the body now refer to the parameter.

  2. Log in to comment