Skip to content

Commit 1f7ebe5

Browse files
committed
[fix] CastConstructor#toFunction expected type
The argument must be of type xs:anyAtomic not item(). Moved the tests to its own module cast-constructor.xqm and expanded the tests.
1 parent 9fb58e6 commit 1f7ebe5

File tree

3 files changed

+79
-23
lines changed

3 files changed

+79
-23
lines changed

exist-core/src/main/java/org/exist/xquery/CastExpression.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public Function toFunction() throws XPathException {
190190
try {
191191
final QName qname = QName.parse(context, typeName);
192192
final FunctionSignature signature = new FunctionSignature(qname);
193-
final SequenceType argType = new SequenceType(Type.ITEM, Cardinality.ZERO_OR_ONE);
193+
final SequenceType argType = new SequenceType(Type.ATOMIC, Cardinality.ZERO_OR_ONE);
194194
signature.setArgumentTypes(new SequenceType[]{argType});
195195
signature.setReturnType(new SequenceType(CastExpression.this.requiredType, CastExpression.this.cardinality));
196196
return new FunctionWrapper(this, signature);

exist-core/src/test/xquery/xquery3/arrowop.xql

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -277,25 +277,3 @@ function ao:for-each-pair-with-contextitem () {
277277
=> for-each-pair((<a/>,<b/>,<a/>,<b/>), function ($a, $b) { node-name($a) || node-name($b) })
278278
=> string-join()
279279
};
280-
281-
(:~
282-
check if CastExpression#toFuntion has correct cardinality check
283-
see https://github.com/eXist-db/exist/issues/4971
284-
:)
285-
declare
286-
%test:assertEmpty
287-
function ao:type-constructor-after-arrow-empty-sequence () {
288-
() => xs:string()
289-
};
290-
291-
declare
292-
%test:assertEquals("1")
293-
function ao:type-constructor-after-arrow-integer () {
294-
1 => xs:string()
295-
};
296-
297-
declare
298-
%test:assertError("XPTY0004")
299-
function ao:type-constructor-after-arrow-integer-sequence () {
300-
(1,2) => xs:string()
301-
};
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(:
2+
: eXist-db Open Source Native XML Database
3+
: Copyright (C) 2001 The eXist-db Authors
4+
:
5+
6+
: http://www.exist-db.org
7+
:
8+
: This library is free software; you can redistribute it and/or
9+
: modify it under the terms of the GNU Lesser General Public
10+
: License as published by the Free Software Foundation; either
11+
: version 2.1 of the License, or (at your option) any later version.
12+
:
13+
: This library is distributed in the hope that it will be useful,
14+
: but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16+
: Lesser General Public License for more details.
17+
:
18+
: You should have received a copy of the GNU Lesser General Public
19+
: License along with this library; if not, write to the Free Software
20+
: Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21+
:)
22+
xquery version "3.1";
23+
24+
module namespace cc="http://exist-db.org/xquery/test/cast-constructor";
25+
26+
declare namespace test="http://exist-db.org/xquery/xqsuite";
27+
28+
(:~
29+
check if CastExpression#toFunction has correct cardinality check
30+
see https://github.com/eXist-db/exist/issues/4971
31+
:)
32+
declare
33+
%test:assertEmpty
34+
function cc:after-arrow-empty-sequence () {
35+
() => xs:string()
36+
};
37+
38+
declare
39+
%test:assertEquals("1")
40+
function cc:after-arrow-integer () {
41+
1 => xs:string()
42+
};
43+
44+
declare
45+
%test:assertError("XPTY0004")
46+
function cc:after-arrow-integer-sequence () {
47+
(1,2) => xs:string()
48+
};
49+
50+
declare
51+
%test:assertEquals("test")
52+
function cc:atomize-element () as xs:string {
53+
xs:string(<div>test</div>)
54+
};
55+
56+
declare
57+
%test:assertEquals("1970-01-01")
58+
function cc:atomize-attribute () as xs:date {
59+
xs:date(attribute when { "1970-01-01" })
60+
};
61+
62+
declare
63+
%test:assertEquals(1)
64+
function cc:atomize-array () as xs:integer {
65+
xs:integer([1])
66+
};
67+
68+
declare
69+
%test:assertError("XPTY0004")
70+
function cc:atomize-array-2 () as xs:string {
71+
xs:string([1,2])
72+
};
73+
74+
declare
75+
%test:assertError("FOTY0013")
76+
function cc:atomize-map-fails () {
77+
xs:integer(map { 0 : 1 })
78+
};

0 commit comments

Comments
 (0)