Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion basex-core/src/main/java/org/basex/query/QueryParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2506,7 +2506,7 @@ private Expr postfix() throws QueryException {
} else if(consume("=?>")) {
expr = methodCall(expr);
} else if(current('(')) {
expr = Functions.dynamic(expr, argumentList(false, null));
expr = dynamicFunctionCall(expr);
} else if(current('?')) {
expr = lookup(expr);
if(expr == null) break;
Expand Down Expand Up @@ -2557,6 +2557,25 @@ private Expr methodCall(final Expr expr) throws QueryException {
return gflwor;
}

/**
* Parses the "DynamicFunctionCall" rule.
* @param expr expression
* @return query expression
* @throws QueryException query exception
*/
private Expr dynamicFunctionCall(final Expr expr) throws QueryException {
final InputInfo info = info();
final FuncBuilder fb = argumentList(false, null);
if(expr.seqType().one()) return Functions.dynamic(expr, fb);
final int s = localVars.openScope();
final For fr = new For(localVars.add(new Var(new QNm("fn"), null, qc, info)), expr);
final VarRef func = new VarRef(info, fr.var);
final Expr call = Functions.dynamic(func, fb);
final GFLWOR gflwor = new GFLWOR(info, fr, call);
localVars.closeScope(s);
return gflwor;
}

/**
* Parses the "PrimaryExpr" rule.
* Parses the "VarRef" rule.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ public Expr optimize(final CompileContext cc) throws QueryException {
if(ft != null) {
if(ft.argTypes != null) {
final int arity = ft.argTypes.length;
if(nargs != arity) throw arityError(func, nargs, arity, false, info);
if(nargs != arity) {
Expr funcItem = func;
if(func instanceof VarRef ref) {
final Expr expr = ref.var.expr();
if(expr instanceof FuncItem) funcItem = expr;
}
throw arityError(funcItem, nargs, arity, false, info);
}
}
if(!sc().mixUpdates && !updating && ft.anns.contains(Annotation.UPDATING)) {
throw FUNCUP_X.get(info, func);
Expand Down
8 changes: 8 additions & 0 deletions basex-core/src/main/java/org/basex/query/var/Var.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ public void expr(final Expr expr) {
ex = expr;
}

/**
* Returns the input expression.
* @return input expression (can be {@code null} if not yet set)
*/
public Expr expr() {
return ex;
}

/**
* Returns the result size.
* @return result size
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public final class HigherOrderTest extends SandboxTest {

/** Test for invalid function expressions. */
@Test public void invalidFunTest() {
error("()()", INVFUNCITEM_X_X);
query("()()", "");

error("1()", INVFUNCITEM_X_X);
error("1.0()", INVFUNCITEM_X_X);
error("1e0()", INVFUNCITEM_X_X);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ public final class SimpleTest extends QueryTest {
{ "Seq 3", integers(1, 2), "((( 1, 2 ) ) )" },
{ "Seq 4", integers(1, 2, 3), "(1, (( 2,3 ) ) )" },
{ "Seq 5", integers(1, 2, 3, 4), "(1, (( 2,3 ) ),4 )" },
{ "Seq 6", "()()" },
{ "Seq 7", "() ()" },
{ "Seq 6", emptySequence(), "()()" },
{ "Seq 7", emptySequence(), "() ()" },

{ "IntersectExcept 1", emptySequence(), "<a/> intersect <b/>" },
{ "IntersectExcept 2", emptySequence(), "<a/> intersect <b/> except <c/>" },
Expand Down
Loading