[ 
https://issues.apache.org/jira/browse/DAFFODIL-2879?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17825731#comment-17825731
 ] 

Steve Lawrence commented on DAFFODIL-2879:
------------------------------------------

> Though, I thought we had an issue where optionals required a predicate? So 
> maybe scalars and optionals can't be allowed either? So maybe a path step can 
> never be ambiguous? It must reference either an array, optional or scala?

I've confirmed that optionals do not require a predicate, in fact optionals are 
not even allowed to have predicates. DAFFODIL-2013 was the issue for this, but 
that bug is just wrong--I've added a test to confirm that is the case.

So, I think it is fine for expressions to ambiguously reference a scalar or 
optional because they are the same from the infosets perspecive--optionals 
might just be missing. But an an expression cannot ambiguously reference an 
array or a scala/optional, because the two implementations are completely 
different.

One potential issue is what if we have an expression like this:

{code}
fn:count(/ambigous/path/to/scalarOrOptional)
{code}

The fn:count function is supposed to be an SDE if it references a scalar 
(DAFFODIL-2711), but maybe if it's ambiguous and it *could* reference an 
optional also then we allow it? So fn:count must unambigously reference either 
an array or non-array, and if it's a non-array then it must be able to 
reference an optional.

> Group evaluation throwing ClassCastException for optional element
> -----------------------------------------------------------------
>
>                 Key: DAFFODIL-2879
>                 URL: https://issues.apache.org/jira/browse/DAFFODIL-2879
>             Project: Daffodil
>          Issue Type: Bug
>          Components: Back End
>    Affects Versions: 3.6.0
>            Reporter: Peter Katlic
>            Priority: Major
>
> A group is defined with an element using fn:count and referenced inside a 
> sequence of array and optional elements. See the test count_21b in 
> daffodil-test/src/test/resources/org/apache/daffodil/section23/dfdl_functions/Functions.tdml
>  for an example.
> Group schema:
> {code:java}
> <xs:group name="countGroup">
>   <xs:sequence>
>     <xs:element name="count" type="xs:int" dfdl:representation="binary" 
> dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/>
>   </xs:sequence>
> </xs:group>{code}
> Sequence schema:
> {code:java}
> <xs:element name="arrayOptional">
>   <xs:complexType>
>     <xs:sequence>
>       <xs:element name="array">
>         <xs:complexType>
>           <xs:sequence>
>             <xs:element name="foo" type="xs:int" minOccurs="2" maxOccurs="2" 
> dfdl:representation="binary"/>
>             <xs:group ref="countGroup"/>
>           </xs:sequence>
>         </xs:complexType>
>       </xs:element>
>       <xs:element name="optional">
>         <xs:complexType>
>           <xs:sequence>
>             <xs:element name="foo" type="xs:int" minOccurs="0" maxOccurs="1" 
> dfdl:representation="binary"/>
>             <!-- throws ClassCastException, possible bug in Daffodil group 
> evaluation -->
>             <!-- <xs:group ref="countGroup"/> -->
>             <xs:element name="count" type="xs:int" 
> dfdl:representation="binary" dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/>
>           </xs:sequence>
>         </xs:complexType>
>       </xs:element>
>     </xs:sequence>
>   </xs:complexType>
> </xs:element>{code}
> Uncommenting 
> {code:java}
> <xs:group ref="countGroup"/>{code}
>  and commenting out 
> {code:java}
> <xs:element name="count" type="xs:int" dfdl:representation="binary" 
> dfdl:inputValueCalc="{ fn:count(../ex:foo) }"/>{code}
>  will produce the following error:
> {code:java}
> java.lang.ClassCastException: class 
> org.apache.daffodil.runtime1.infoset.DISimple cannot be cast to class 
> org.apache.daffodil.runtime1.infoset.DIArray{code}
> It seems as if the optional is evaluated as a DownArray instead of a 
> DownElement.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to