Fix function call statement passes Variable expression instead of function name value

This commit is contained in:
aNNiMON 2023-10-03 22:48:43 +03:00 committed by Victor Melnik
parent 3e661c81c4
commit 34298bceb8
2 changed files with 11 additions and 9 deletions

View File

@ -160,7 +160,7 @@ public final class Parser {
return classDeclaration();
}
if (lookMatch(0, TokenType.WORD) && lookMatch(1, TokenType.LPAREN)) {
return new ExprStatement(functionChain(qualifiedName()));
return functionCallStatement();
}
return assignmentStatement();
}
@ -321,6 +321,12 @@ public final class Parser {
return statementOrBlock();
}
private ExprStatement functionCallStatement() {
return new ExprStatement(
functionChain(new ValueExpression(consume(TokenType.WORD).text()))
);
}
private Expression functionChain(Expression qualifiedNameExpr) {
// f1()()() || f1().f2().f3() || f1().key
final Expression expr = function(qualifiedNameExpr);

View File

@ -45,15 +45,11 @@ public final class FunctionalExpression extends InterruptableNode implements Exp
}
private Function consumeFunction(Expression expr) {
try {
final Value value = expr.eval();
if (value.type() == Types.FUNCTION) {
return ((FunctionValue) value).getValue();
}
return getFunction(value.asString());
} catch (VariableDoesNotExistsException ex) {
return getFunction(ex.getVariable());
}
}
private Function getFunction(String key) {