armoha / euddraft

System for pluginizing eudplib codes.
Other
29 stars 4 forks source link

[epScript] Unexpected Aliasing in Declaring and initializing multiple variables #51

Closed armoha closed 2 years ago

armoha commented 2 years ago
// example code
var a, b = 1, 2;
function onPluginStart() {
    var p = a;  // normal behavior: declare new variable `p` and initialize its value with `a`
    var q, r = a, b;  // bug: NO allocation occurs. q, r are 'alias' of a, b; they point to same variables.
    py_exec("assert a is q and b is r");  // evaluated as True, assertion passes
    q, r = 3, 4;
    simpleprint(a, b);  // prints "3 4"
}

Major bug, should be fixed ASAP.

armoha commented 2 years ago

Reproduced in euddraft 0.9.4.8 and 0.8.2.9.

This is NOT a recent regression but long-standing bug (more than 4 years ago).

armoha commented 2 years ago
    # __epspy__ analysis
    # (Line 4) var p = a;  // declare new variable `p` and initialize its value with `a`
    p = EUDVariable()
    p << (a)
    # (Line 5) var q, r = a, b;  // NO allocation occurs. q, r are 'alias' of a, b; they point to same variables.
    q, r = _MVAR([a, b])

# related epScript helper function
def _MVAR(vs):
    return List2Assignable([
        v.makeL() if IsEUDVariable(v) else EUDVariable() << v
        for v in FlattenList(vs)])

# eudplib/core/varialbe/eudv.py
# class EUDVariable
    def makeL(self):
        self._rvalue = False
        return self
armoha commented 2 years ago

Should be fixed in https://github.com/armoha/eudplib/commit/db3e0b09748c6582b43118c0073faf84d726a286