Message Boards Message Boards

GROUPS:

Bug with Block & Lookup: Scope Variable Leak.

Posted 11 months ago
696 Views
|
0 Replies
|
9 Total Likes
|

After debugging a large chunk of code, I could identify this MWE.

ClearAll@test
test[var_String]:= Block[{association},
    association = <|"x"-> <|"key01"-> "ok"|>|>[var];
    Lookup[association,"key01",{}]
]

If I evaluate:

test["x"]
test["y"]
test["x"]

I get an error evaluating the last test["x"]. What is very strange, I expected to find an error just in the evaluation of test["y"].

The same error does not occur if we change from Block to Module. In the Block case, we have some sort of unexpected scope leak. Looks like a bug in Lookup.

Tested in Mathematica version 11.3
Cross post in Stack Exchange

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract