Open ewoutkramer opened 12 months ago
This is related to these two optional command arguments:
disable-list-demotion | | Disables demotion of list-valued expressions to singletons -- | -- | -- disable-list-promotion | | Disables promotion of singletons to list-valued expressionsBy default list demotion & promotion is enabled in the command line tool.
Fundamentally, these command line features act as implicit cast operators.
In C#, the is
and as
keywords do not invoke implicit conversion operators, for good reason.
It is imperative that CQL give you an ability to determine at runtime what an object actually is. For example, consider this code:
define function "What is this?"(any System.Any):
case
when any is System.Boolean then ...
when any is List<System.Boolean> then...
else ...
If implicit conversion operators are allowed to apply to operands of the is
operator, this code becomes non-deterministic, because the case
operator does not demand that the when
statements be evaluated in the order they appear.
If anything, I'd expect the opposite behavior. is
should never invoke an implicit conversion, but as
could.
The CQL spec never explicitly states that the arguments to
is/as/cast as
are exempt from automatic promotion/demotion, although it probably makes sense (and would be consistent with the behaviour of, say, the C#as
andis
, which also will not do implicit conversions).Trying to reverse engineer the Java engines behaviour I noticed this:
which leads me to think that in the Java engine promotion does apply to the
is
operator, but not to theas
, which seems inconsistent to me. ("So some x is of type Y but I cannot actually cast it to Y?").