arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
673 stars 29 forks source link

Fix AST handling of method calls #1625

Closed drkameleon closed 1 month ago

drkameleon commented 1 month ago

Description

Right now, this:

define :person [
    init: constructor [
        name :string
        surname :string
    ]

    check: method [][
        inspect this
    ]
]

define :personWrapper [
    init: method [n, s][
        \pers: to :person @[n, s]
    ]

    doSth: method [][
        \pers\check
    ]
]

a: to :personWrapper ["John" "Doe"]!
a\doSth

b: to :personWrapper ["Jane" "Doe"]!
b\doSth

leads to this:

[ :person
        name     :        John :string
        surname  :        Doe :string
]
[ :person
        name     :        John :string
        surname  :        Doe :string
]

The cause is that this\pers inside doSth has already been embedded the first time the function was evaluated. And since - for performance reasons - we tend to store evaluated blocks (apparently, a bit too much), the next time this function is called, with a different object, the same one is getting served πŸ€¦πŸ»β€β™‚οΈ .

So, let's fix it!

Type of change

drkameleon commented 1 month ago

Ready to merge! πŸš€