Skip to content

Commit b032a42

Browse files
authored
Merge pull request eXist-db#4848 from line-o/cleanup/remove-deprecated-filter-fn
Cleanup/remove deprecated filter fn
2 parents 0b1ef35 + 3ba391e commit b032a42

File tree

3 files changed

+8
-30
lines changed

3 files changed

+8
-30
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>

extensions/modules/expathrepo/src/main/resources/org/exist/xquery/modules/expathrepo/repair.xql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ declare %private function repair:repair-callback($collection as xs:anyURI, $incl
8585
};
8686

8787
declare function repair:is-installed($name as xs:string) as xs:boolean {
88-
exists(filter(function($pkg) { $pkg = $name }, repo:list()))
88+
exists(filter(repo:list(), function($pkg) { $pkg = $name }))
8989
};
9090

9191
(:~ Scan a collection tree recursively starting at $root. Call $func once for each collection found :)
@@ -97,9 +97,9 @@ declare %private function repair:scan-collections($root as xs:anyURI, $func as f
9797
};
9898

9999
declare %private function repair:find-resources-to-zip($collection as xs:anyURI) {
100-
filter(function($name) {
100+
filter(xmldb:get-child-resources($collection), function($name) {
101101
$name = ("expath-pkg.xml", "repo.xml", "exist.xml") or starts-with($name, "icon")
102-
}, xmldb:get-child-resources($collection))
102+
})
103103
};
104104

105105
declare %private function repair:resources-to-zip($expathConf as element(expath:package), $collection as xs:anyURI) {

0 commit comments

Comments
 (0)