Skip to content

Commit 1791c26

Browse files
committed
[fix] remove deprecated fn:filter syntax
Six years ago the spec for fn:filter changed. As it was already used in some applications like dashboard, existdb allowed both ways to call fn:filter. This commit removes the special handling, where the parameters are flipped. This will now throw an XPTY0004 for wrong parameter type.
1 parent 0b1ef35 commit 1791c26

File tree

2 files changed

+5
-27
lines changed

2 files changed

+5
-27
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FunHigherOrderFun.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,6 @@ public FunHigherOrderFun(XQueryContext context, FunctionSignature signature) {
112112
super(context, signature);
113113
}
114114

115-
@Override
116-
protected void checkArgument(final Expression arg, @Nullable final SequenceType argType,
117-
final AnalyzeContextInfo argContextInfo, final int argPosition) throws XPathException {
118-
// hack: order of parameters for filter and other functions has changed
119-
// in final XQ3 spec. This would cause some core apps (dashboard) to stop
120-
// working. We thus switch parameters dynamically until all users can be expected to
121-
// have updated to 2.2.
122-
if (!isCalledAs("filter")) {
123-
super.checkArgument(arg, argType, argContextInfo, argPosition);
124-
}
125-
}
126-
127115
@Override
128116
public void analyze(AnalyzeContextInfo contextInfo) throws XPathException {
129117
cachedContextInfo = new AnalyzeContextInfo(contextInfo);
@@ -149,24 +137,14 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence)
149137
}
150138
}
151139
} else if (isCalledAs("filter")) {
152-
final FunctionReference refParam;
153-
final Sequence seq;
154-
// Hack: switch parameters for backwards compatibility
155-
if (Type.subTypeOf(args[1].getItemType(), Type.FUNCTION_REFERENCE)) {
156-
refParam = (FunctionReference) args[1].itemAt(0);
157-
seq = args[0];
158-
} else {
159-
refParam = (FunctionReference) args[0].itemAt(0);
160-
seq = args[1];
161-
}
162-
163-
try (final FunctionReference ref = refParam) {
140+
try (final FunctionReference ref = (FunctionReference) args[1].itemAt(0)) {
164141
ref.analyze(cachedContextInfo);
165142
if (funcRefHasDifferentArity(ref, 1)) {
166143
throw new XPathException(this, ErrorCodes.XPTY0004,
167144
"The supplied function (" + ref.getStringValue() + ") has " + ref.getSignature().getArgumentCount() + " arguments - expected 1");
168145
}
169146

147+
final Sequence seq = args[0];
170148
for (final SequenceIterator i = seq.iterate(); i.hasNext(); ) {
171149
final Item item = i.nextItem();
172150
final Sequence r = ref.evalFunction(null, null, new Sequence[]{item.toSequence()});

exist-core/src/test/xquery/xquery3/higher-order.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,11 +499,11 @@ return
499499
</test>
500500
<test output="text">
501501
<task>fn:filter function (wrong argument order: deprecated)</task>
502-
<code>fn:filter(function($a) {$a mod 2 = 0}, 1 to 10)</code>
503-
<expected>2 4 6 8 10</expected>
502+
<code>fn:filter(function($a) {$a mod 2 = 0}, (1 to 10))</code>
503+
<error>XPTY0004</error>
504504
</test>
505505
<test output="text">
506-
<task>fn:filter function (correct argument order)</task>
506+
<task>fn:filter function</task>
507507
<code>fn:filter(1 to 10, function($a) {$a mod 2 = 0})</code>
508508
<expected>2 4 6 8 10</expected>
509509
</test>

0 commit comments

Comments
 (0)