www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 8221] New: typeof(null) rejected as return type for covariant overrides

reply d-bugmail puremagic.com writes:
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



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: -------
Jun 11 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221


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

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



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: -------
Jun 11 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221


Walter Bright <bugzilla digitalmars.com> changed:

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



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: -------
Jun 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Jun 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221





 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: -------
Jun 13 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221




00:39:47 PDT ---

 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: -------
Jun 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221






 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: -------
Jun 14 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=8221




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


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: -------
Jun 22 2012
prev sibling parent d-bugmail puremagic.com writes:
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: -------
Jun 22 2012