www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5450] New: no match for implicit super() call in constructor

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450

           Summary: no match for implicit super() call in constructor
           Product: D
           Version: D1 & D2
          Platform: Other
        OS/Version: All
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: mrmocool gmx.de


--- Comment #0 from Trass3r <mrmocool gmx.de> 2011-01-13 06:12:02 PST ---
class Foo
{
    this(float f) {}
}

class Bar : Foo
{
    this(int i) {}
}

-> foo.d(8): Error: constructor foo.Bar.this no match for implicit super() call
in constructor

Adhering to the spec, dmd silently inserts a super() call in Bar's constructor
as soon as its base class Foo has *a* constructor. But there is no this()
without arguments in Foo.

This always requires me to put a bugging this() {} into Foo.

Why can't dmd just generate an empty this(){} in this case?
I mean it also does it the other way around:

"If there is no constructor for a class, but there is a constructor for the
base class, a default constructor of the form: this() { } is implicitly
generated."

(Though the spec could be clearer here, does this also mean that a super() call
is inserted into this newly generated this()?)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 13 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2011-01-13 07:00:28 PST ---
As soon as you add a constructor to Foo, you disable the implicit constructor.
So it's correct for the compiler to complain.
Probably the wording of the error message could be improved, but I don't think
this is a rejects-valid bug.

(In reply to comment #0)
 I mean it also does it the other way around:
No, it doesn't. See below:
 "If there is no constructor for a class, but there is a constructor for the
 base class, a default constructor of the form: this() { } is implicitly
 generated."
 
 (Though the spec could be clearer here, does this also mean that a super() call
 is inserted into this newly generated this()?)
Yes. And look what it does: class Foo { this(float f) {} } class Bar : Foo { } -> foo.d(7): Error: constructor foo.Bar.this no match for implicit super() call in constructor Actually it shouldn't insert an implicit this() unless the base class has a this(). Instead, it should complain that Bar needs a constructor, because Foo has one. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450



--- Comment #2 from Trass3r <mrmocool gmx.de> 2011-01-13 09:49:40 PST ---
(In reply to comment #1)
 
 class Foo
 {
     this(float f) {}
 }
 
 class Bar : Foo
 {
 }
 
 -> foo.d(7): Error: constructor foo.Bar.this no match for implicit super() call
 in constructor
 
 Actually it shouldn't insert an implicit this() unless the base class has a
 this(). Instead, it should complain that Bar needs a constructor, because Foo
 has one.
Then this bug report's focus should move to your example I think. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 13 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|rejects-valid, spec         |
                 CC|                            |bugzilla digitalmars.com
           Severity|normal                      |minor


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2012-01-23
23:52:25 PST ---
The only bug here is it could be a better error message.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 23 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-07
18:37:59 PST ---
(In reply to comment #3)
 The only bug here is it could be a better error message.
A shame I haven't noticed this report before fixing Issue 8928. The error is now: "Error: constructor foo.Bar.this no match for implicit super() call in implicitly generated constructor" But I could revert the fix for 8298 and instead avoid generating the ctor at all and printing: "Error: class foo.Bar cannot implicitly generate a default ctor when base class foo.Foo is missing a default ctor" -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jan 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com


--- Comment #5 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-01-07
18:45:54 PST ---
https://github.com/D-Programming-Language/dmd/pull/1439

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 07 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450



--- Comment #6 from github-bugzilla puremagic.com 2013-03-07 18:15:05 PST ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/291dfade1750cd297491e8d17332036d75c23897
Fixes Issue 5450 - Don't generate default ctor if base class lacks default
ctor.

https://github.com/D-Programming-Language/dmd/commit/14d466438f3e2714dbda6672645653d472c7bcd2
Merge pull request #1439 from AndrejMitrovic/Fix5450

Issue 5450 - Don't generate default ctor if base class lacks default ctor

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 07 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5450


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: -------
Mar 07 2013