seastan / dragncards

Multiplayer online card game platform written in Elixir, Phoenix, and React. Drag and Drop provided by React-Beautiful-DND.
https://dragncards.com/
79 stars 41 forks source link

Function argument name clash bug #97

Closed morvael closed 3 months ago

morvael commented 3 months ago

Consider this code:

        "NAME_OVERRIDE_TEST": {
            "args": ["$A", "$B"],
            "code": [
                ["LOG", "A is {{$A}}, B is {{$B}}"]
            ]
        },
        "NAME_OVERRIDE_TEST_FAIL": {
            "args": [],
            "code": [
                ["VAR", "$A", "A"],
                ["VAR", "$B", "B"],
                ["NAME_OVERRIDE_TEST", "$B", "$A"]                
            ]
        }

(call NAME_OVERRIDE_TEST_FAIL)

Expected output is: A is B, B is A What you get is: A is B, B is B

This happens because argument names are probably not resolved until some code akin to this one is ran before main function body:

["VAR", "$A", "$B"],
["VAR", "$B", "$A"],

Second assignment fails, since argument value was overwritten in first assignment.

This is kind of a blocker, it's hard to require variables at outer level to be always named differently than arguments inside function...

seastan commented 3 months ago

Introduced MULTI_VAR, which I now use when setting variables for functions. Let me know if you are able to break it now.

morvael commented 3 months ago

image

Looks like it's ok now.