Skip to content

Commit 34298bc

Browse files
committed
Fix function call statement passes Variable expression instead of function name value
1 parent 3e661c8 commit 34298bc

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

ownlang-parser/src/main/java/com/annimon/ownlang/parser/Parser.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ private Statement statement() {
160160
return classDeclaration();
161161
}
162162
if (lookMatch(0, TokenType.WORD) && lookMatch(1, TokenType.LPAREN)) {
163-
return new ExprStatement(functionChain(qualifiedName()));
163+
return functionCallStatement();
164164
}
165165
return assignmentStatement();
166166
}
@@ -321,6 +321,12 @@ private Statement statementBody() {
321321
return statementOrBlock();
322322
}
323323

324+
private ExprStatement functionCallStatement() {
325+
return new ExprStatement(
326+
functionChain(new ValueExpression(consume(TokenType.WORD).text()))
327+
);
328+
}
329+
324330
private Expression functionChain(Expression qualifiedNameExpr) {
325331
// f1()()() || f1().f2().f3() || f1().key
326332
final Expression expr = function(qualifiedNameExpr);

ownlang-parser/src/main/java/com/annimon/ownlang/parser/ast/FunctionalExpression.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,11 @@ public Value eval() {
4545
}
4646

4747
private Function consumeFunction(Expression expr) {
48-
try {
49-
final Value value = expr.eval();
50-
if (value.type() == Types.FUNCTION) {
51-
return ((FunctionValue) value).getValue();
52-
}
53-
return getFunction(value.asString());
54-
} catch (VariableDoesNotExistsException ex) {
55-
return getFunction(ex.getVariable());
48+
final Value value = expr.eval();
49+
if (value.type() == Types.FUNCTION) {
50+
return ((FunctionValue) value).getValue();
5651
}
52+
return getFunction(value.asString());
5753
}
5854

5955
private Function getFunction(String key) {

0 commit comments

Comments
 (0)