Thread overview
[Issue 8221] New: typeof(null) rejected as return type for covariant overrides
Jun 11, 2012
timon.gehr@gmx.ch
Jun 12, 2012
Kenji Hara
Jun 14, 2012
Walter Bright
Jun 14, 2012
Walter Bright
Jun 14, 2012
Kenji Hara
Jun 14, 2012
Walter Bright
Jun 14, 2012
Kenji Hara
Jun 23, 2012
Walter Bright
June 11, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221

           Summary: typeof(null) rejected as return type for covariant
                    overrides
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: timon.gehr@gmx.ch


--- Comment #0 from timon.gehr@gmx.ch 2012-06-11 08:20:54 PDT ---
DMD 2.059:

class A{
    A foo(){return this;}
}
class B: A{
    override typeof(null) foo(){return null;} // error
}

The code should compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 12, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #1 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-11 20:16:59 PDT ---
https://github.com/D-Programming-Language/dmd/pull/1001

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #2 from Walter Bright <bugzilla@digitalmars.com> 2012-06-13 22:50:28 PDT ---
Why should this compile? What is the compelling reason?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221



--- Comment #3 from Kenji Hara <k.hara.pg@gmail.com> 2012-06-13 23:05:57 PDT ---
(In reply to comment #2)
> Why should this compile? What is the compelling reason?

typeof(null) is a subtype of array/class/pointer types. By return type covariance rule, B.foo should be able to override A.foo.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221



--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-06-14 00:39:47 PDT ---
(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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221



--- Comment #5 from Kenji Hara <k.hara.pg@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: -------
June 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221



--- Comment #6 from github-bugzilla@puremagic.com 2012-06-22 21:31:29 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/bc55af9d3d38fd18f3a2c1f323cd1a4f49dbd673 fix Issue 8221 - typeof(null) rejected as return type for covariant overrides

https://github.com/D-Programming-Language/dmd/commit/ad7637f3d3c2cdf98ff7de8d715315e8557ee223 Merge pull request #1001 from 9rnsr/fix8221

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

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 23, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=8221


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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