Bug 9739 – Regression (1.077 git-head): DMD not considering ctor with default args as default ctor

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2013-03-16T20:06:00Z
Last change time
2013-04-13T14:58:51Z
Keywords
rejects-valid
Assigned to
nobody
Creator
puneet

Comments

Comment #0 by puneet — 2013-03-16T20:06:54Z
Compiles with 2.062. But with the latest github snapshot, gives me an error: $ rdmd --force test.d test.d(5): Error: class test.Bar Cannot implicitly generate a default ctor when base class test.Foo is missing a default ctor Failed: 'dmd' '-v' '-o-' 'test.d' '-I.' class Foo { this(int arg=0) { } } class Bar: Foo { } void main() { Bar test = new Bar; }
Comment #1 by andrej.mitrovich — 2013-03-16T20:46:04Z
This is caused by: https://github.com/D-Programming-Language/dmd/pull/1439 I think I've already tried to change how the 'defaultCtor' field is set, but I think that change got rejected, or maybe it was part of a pull that wasn't yet merged. In hindsight I should have written more elaborate tests. @Kenji: Do you know why the code which sets `ad->defaultCtor = this;` doesn't check for defaulted parameters? That code is at the end of `CtorDeclaration::semantic`
Comment #2 by k.hara.pg — 2013-04-03T18:27:10Z
(In reply to comment #1) > This is caused by: > https://github.com/D-Programming-Language/dmd/pull/1439 > > I think I've already tried to change how the 'defaultCtor' field is set, but I > think that change got rejected, or maybe it was part of a pull that wasn't yet > merged. > > In hindsight I should have written more elaborate tests. > > @Kenji: Do you know why the code which sets `ad->defaultCtor = this;` doesn't > check for defaulted parameters? That code is at the end of > `CtorDeclaration::semantic` Because ad->defaultCtor should not have any parameters. Its function pointer will be stored in TypeInfo_Class.defaultConstructor, so storing `this(int arg=0)` in it would cause access violation in runtime. https://github.com/D-Programming-Language/druntime/blob/master/src/object_.d#L853 https://github.com/D-Programming-Language/dmd/blob/master/src/toobj.c#L585
Comment #3 by k.hara.pg — 2013-04-03T19:22:21Z
Comment #4 by github-bugzilla — 2013-04-03T21:47:58Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/7ab0211e68815663cf84aa0cf98425f0f6e4bade fix Issue 9739 - DMD not considering ctor with default args as default ctor https://github.com/D-Programming-Language/dmd/commit/8a2a36894eecb96f32eee7db377308e277791032 Merge pull request #1833 from 9rnsr/fix9739 [REG2.063a] Issue 9739 - DMD not considering ctor with default args as default ctor
Comment #5 by andrej.mitrovich — 2013-04-12T08:49:18Z
*** Issue 9925 has been marked as a duplicate of this issue. ***
Comment #6 by leandro.lucarella — 2013-04-12T08:53:30Z
This is still present in D1.
Comment #7 by leandro.lucarella — 2013-04-12T08:59:47Z
Comment #8 by leandro.lucarella — 2013-04-12T09:04:06Z
(In reply to comment #7) > https://github.com/D-Programming-Language/dmd/pull/1892 Nope, doesn't work, it was a literal backport of D2 fix but D1 doesn't have resolveFuncCall(). So I guess something else needs to be done. Would probably be even better to revert the change that caused it in D1 if a better solution is hard to implement (see issue 9925).
Comment #9 by leandro.lucarella — 2013-04-12T09:24:08Z
Pull updated with a fixed fix :P
Comment #10 by github-bugzilla — 2013-04-13T10:22:29Z
Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/9ba9925641f224ae33c756791de12eab656f04a0 Merge pull request #1892 from leandro-lucarella-sociomantic/fix9739-d1 [D1] fix Issue 9739 - DMD not considering ctor with default args as default ctor