[Issue 8221] typeof(null) rejected as return type for covariant overrides

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jun 14 01:11:14 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=8221



--- Comment #5 from Kenji Hara <k.hara.pg at gmail.com> 2012-06-14 01:13:26 PDT ---
(In reply to comment #4)
> (In reply to comment #3)
> > typeof(null) is a subtype of array/class/pointer types. By return type
> > covariance rule, B.foo should be able to override A.foo.
> 
> Since A is not a base class of null, I do not think this is valid. foo could
> return B, and that will work, because A is a base class of B.

No. Indeed A is not a base class of null _liteal_, but A is a base _type_ of
typeof(null).
Current dmd compiles following tests:

static assert(is(typeof(null) : int[]));  // int[]  is a base type of
typeof(null)
static assert(is(typeof(null) : Object)); // Object is a base type of
typeof(null)
static assert(is(typeof(null) : int*));   // int*   is a base type of
typeof(null)

I have implemented typeof(null) as like Scala's Nothing type, so this is
expected result.

In other words, typeof(null) is the most derived class type from all of class
types. So dmd should compile the original code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list