Bug 5450 – no match for implicit super() call in constructor
Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-01-13T06:12:00Z
Last change time
2015-06-09T05:11:38Z
Keywords
pull
Assigned to
andrej.mitrovich
Creator
hoganmeier
Comments
Comment #0 by hoganmeier — 2011-01-13T06:12:02Z
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()?)
Comment #1 by clugdbug — 2011-01-13T07:00:28Z
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.
Comment #2 by hoganmeier — 2011-01-13T09:49:40Z
(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.
Comment #3 by bugzilla — 2012-01-23T23:52:25Z
The only bug here is it could be a better error message.
Comment #4 by andrej.mitrovich — 2013-01-07T18:37:59Z
(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"
Comment #5 by andrej.mitrovich — 2013-01-07T18:45:54Z