stevedlawrence commented on issue #159: Restrict coercion of a whole expression
URL: 
https://github.com/apache/incubator-daffodil/pull/159#issuecomment-451214473
 
 
   Came back to this to add some negative tests, and I dont' think this is 
really the complete solution. This change still allows coercion in the case 
where the target type and the expression result type are both numeric. This is 
clearly wrong in the case of decimal numbers, for example:
   
   ```xml
   <xs:element name="a" type="xs:int" dfdl:inputValueCalc="{ 2.5 }" />
   ```
   In this case, we really do not want to coerce 2.5 to an int, but this change 
would coerce since both are numerics.  An alternative might be to require that 
types match exactly, but then usability suffers. For example:
   
   ```xml
   <xs:element name="a" type="xs:int" dfdl:inputValueCalc="{ 2 }" />
   ```
   
   In this case, the literal 2 is technically an xs:integer so the result type 
and target type do not match. So if we were strict about it, this simple 
expression requires the use of ``xs:int(2)``. That's not terrible, but there's 
a good chance we would probably break a lot of schemas.
   
   Perhaps a happy medium is to allow coercion between integer-like things? So 
we would automatically coerece an xs:integer to an xs:int (as long as the value 
was in range), but would not coerece 2.5 to 2, for example. An odd side effect 
of this is that one could know do this:
   
   ```xml
   <xs:element name="a" type="xs:int" dfdl:inputValueCalc="{ xs:integer(2) }" />
   ```
   
   And we would happily coerce that, even though it seems like maybe the user 
intended something else since types are explicitly provided and differ. Perhaps 
a better solution exists? I think it would be difficult track track when types 
are explicit and only check in those cases, so maybe this edge case isn't worth 
solving.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to