fix double-eval of this arguments (#700)

This commit is contained in:
Marcin Kostrzewa 2020-04-29 16:59:07 +02:00 committed by GitHub
parent d03a5a9dde
commit 1254920482
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -167,6 +167,7 @@ public abstract class InvokeCallableNode extends BaseNode {
Stateful selfResult = thisExecutor.executeThunk((Thunk) selfArgument, state);
selfArgument = selfResult.getValue();
state = selfResult.getState();
arguments[thisArgumentPosition] = selfArgument;
}
Function function = methodResolverNode.execute(symbol, selfArgument);
return this.invokeFunctionNode.execute(function, callerFrame, state, arguments);

View File

@ -13,6 +13,17 @@ class MethodsTest extends InterpreterTest {
eval(code) shouldEqual 11
}
"Method calls" should "execute `this` argument once" in {
val code =
"""
|Unit.foo = 0
|
|main = (IO.println "foo").foo
|""".stripMargin
eval(code)
consumeOut shouldEqual List("foo")
}
"Methods" should "be callable with dot operator" in {
val code =
"""