hi EC
Last meeting we talked about how $cast should behave when its
first (target) argument is a class handle variable, and its
second (source) argument is an expression whose value is null.
I've created Mantis 3293 to capture this.
Given the increased complexity introduced here by the multiple
inheritance proposals, I'd be glad to know what behaviour
people think is desirable before I put any effort into a
proposal. It seems to me that there are several situations:
- If the source expression's statically determined type is a
descendant of, or equivalent to, the target type, then a
simple copy would be OK so it seems reasonable for the
$cast to succeed unconditionally, and be compiled as a
simple copy operation - so it would succeed if the source
is null, too. Current tools have $cast succeed if the
source is null, in this case.
- If the source expression's statically determined type is
on a different branch of the hierarchy from the target's,
then in SV-2009 the cast is sure to fail; having it succeed
if the source happens to be null sounds unsatisfactory to me.
However, if we have multiple inheritance then things are not
so simple; the cast is no longer sure to fail, but I would
guess that it should still be an error if the source is null.
Current tools disagree about this already.
- If the source expression's statically determined type is
an ancestor of the target's, what should happen if the
source is null? Current simulators all say "cast succeeds",
but is this correct?
- If the source expression is the special value "null", should
the rules be any different than if the source is some other
expression that happens to give a null value?
Finally, can someone kindly remind me about this subtlety, which
I seem to remember was dealt with for 2009 but I can't find the
relevant Mantis. Given these declarations:
class C; ...
class D extends C; ...
C c;
D d;
bit b;
what do we say about the data type of this expression?
b ? c : d
Is d effectively upcast to C before being returned, so the
expression as a whole has type C?
Thanks
-- Jonathan Bromley -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.Received on Sun Nov 21 14:26:51 2010
This archive was generated by hypermail 2.1.8 : Sun Nov 21 2010 - 14:27:13 PST