exist
exist copied to clipboard
[BUG] return type tests incorrect or incomplete
tldr; seems that for function return types ElementTest (or just a very basic one) and no TypedArrayTest is performed.
Describe the bug
When writing a function with a explicitly declared return type, the return type is just checked very basically, but not in accordance to specs. The return type element()
is checked for, but a more specified version like element(x:y)
is not evaluated besides the basic check.
Same happens for array()
and array(xs:string)
: Basic check is done correctly, but no check for data types inside the array.
This is confusing especially because of the expected correct behavior for input types. Input types are check correctly.
With less details this is reported in the comment here.
Expected behavior Types should be evaluated not only on the basic level.
To Reproduce
correct behavior
Error is thrown before the problematic return type check is done, but the examples below show that the type check is done correctly and on a deeper level.
xquery version "3.1";
declare namespace x="httpx://x/ns/1.0";
declare function local:test($test as element(x:what))
as element(x:test){
<x:what/>
};
let $element as element() := <x:element/>
return
local:test($element)
exerr:ERROR Type error in expression: required node name is x:what; got: x:element [at line 13, column 17 …
xquery version "3.1";
declare namespace x="httpx://x/ns/1.0";
declare function local:test($test as element(x:what))
as element(x:test){
<x:what/>
};
let $element as element(x:test) := <x:what/>
return
local:test($element)
err:XPTY0004 Invalid type for variable $element. Expected element(), got element() [at line 11, column 6 …
problematic behavior
xquery version "3.1";
declare namespace x="httpx://x/ns/1.0";
declare function local:test($test as element(x:element))
as element(x:test){
<x:what/>
};
let $element as element(x:element) := <x:element/>
return
local:test($element)
<x:what xmlns:x="httpx://x/ns/1.0"/> Which is a return that is not allowed by the function, see ElementTest.
also a very basic example is not throwing an error:
xquery version "3.1";
let $array as array(xs:string+) := array{ 1,2,3 }
return
$array
but also as a function return, it seems no TypedArrayTest is performed.
Context (please always complete the following information):
- OS: fedora linux
- eXist-db version: 5.3.0-SNAPSHOT (2021-03-19 via docker existdb:latest)
- openjdk version "1.8.0_282"
Additional context
- How is eXist-db installed? docker
- Any custom changes in e.g.
conf.xml
? No. Justdocker run
.
related to https://github.com/eXist-db/exist/pull/3389
Is this a dupe of https://github.com/eXist-db/exist/issues/1917?
Is this a dupe of #1917?
#1917 is an additional problem. Processor should check for cardinality as well, but here the ElementTest and TypedArrayTests are referred. May be both issues should get attention, may be they can be fixed together, but i think they are different. (Of course i checked at least the topics of existing issues w/ term "type" :-) ) but it is mentioned in the comment: https://github.com/eXist-db/exist/issues/1917#issuecomment-723598283
related to #3389
and I did not check existing PRs. :+1: thanks @line-o
@mathias-goebel Great! Thank you for the tests and explanation.