Skip to content
Open
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
12 changes: 6 additions & 6 deletions exist-core/src/main/java/org/exist/xquery/ForExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,12 @@ public Sequence eval(Sequence contextSequence, Item contextItem)
if (sequenceType != null) {
//Type.EMPTY is *not* a subtype of other types ; checking cardinality first
//only a check on empty sequence is accurate here
if (resultSequence.isEmpty() &&
!sequenceType.getCardinality().isSuperCardinalityOrEqualOf(Cardinality.EMPTY_SEQUENCE))
{throw new XPathException(this, ErrorCodes.XPTY0004,
"Invalid cardinality for variable $" + varName + ". Expected " +
sequenceType.getCardinality().getHumanDescription() +
", got " + Cardinality.EMPTY_SEQUENCE.getHumanDescription());}
// if (resultSequence.isEmpty() &&
// !sequenceType.getCardinality().isSuperCardinalityOrEqualOf(Cardinality.EMPTY_SEQUENCE))
// {throw new XPathException(this, ErrorCodes.XPTY0004,
// "Invalid cardinality for variable $" + varName + ". Expected " +
// sequenceType.getCardinality().getHumanDescription() +
// ", got " + Cardinality.EMPTY_SEQUENCE.getHumanDescription());}
//TODO : ignore nodes right now ; they are returned as xs:untypedAtomicType
if (!Type.subTypeOf(sequenceType.getPrimaryType(), Type.NODE)) {
if (!resultSequence.isEmpty() &&
Expand Down
12 changes: 12 additions & 0 deletions exist-core/src/test/java/org/exist/xquery/XQueryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2452,6 +2452,18 @@ public void wrongInvalidTypeError_1787285() throws XMLDBException {
}
}

@Test
public void typedForVariableWithEmptyReturn_5050() throws XMLDBException {
final String query = "for $x as xs:string in 'X' return ()";
try (final Collection testCollection = getTestCollection()) {
final XPathQueryService service = testCollection.getService(XPathQueryService.class);
try (final EXistResourceSet result = (EXistResourceSet) service.query(query)) {
assertEquals(0, result.getSize());
}
}
}


/**
* Regression
*
Expand Down
Loading