Bug 8742 – Anonymous nested class derived from another nested class makes DMD crash

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-10-01T06:29:00Z
Last change time
2015-06-09T05:11:56Z
Keywords
ice, pull
Assigned to
nobody
Creator
david.eckardt

Comments

Comment #0 by david.eckardt — 2012-10-01T06:29:21Z
When compiling the following example module, DMD 1.075 or 2.060 crashes with Segmentation Fault with -version=Crash; it does not without. --- module crash; class C { class D { } } void main ( ) { auto c = new C; version(Crash) auto d = c.new class C.D { }; } ---
Comment #1 by andrej.mitrovich — 2013-01-10T07:30:02Z
Is this valid code to begin with? @Kenji @Walter: `toParent2()->getType()` returns NULL, hence isBaseOf crashes when it tries to call `t->ty` on a NULL `t`. I can add a check to `isBaseOf`, then it will return: test.d(11): Error: class test.main.__anonclass1 is nested within main, but super class D is nested within C test.d(11): Error: e.new is only for allocating nested classes So it would turn the ICE into an error, but is that ok or is the code actually valid?
Comment #2 by david.eckardt — 2013-01-10T10:43:28Z
It sounds plausible to me that the code is invalid due to wrong nesting; I didn't notice that, sorry.
Comment #3 by k.hara.pg — 2013-01-11T00:12:02Z
(In reply to comment #1) > Is this valid code to begin with? > > @Kenji @Walter: `toParent2()->getType()` returns NULL, hence isBaseOf crashes > when it tries to call `t->ty` on a NULL `t`. I can add a check to `isBaseOf`, > then it will return: > > test.d(11): Error: class test.main.__anonclass1 is nested within main, but > super class D is nested within C > test.d(11): Error: e.new is only for allocating nested classes > > So it would turn the ICE into an error, but is that ok or is the code actually > valid? Seems reasonable. In the case, anonymous class typeof(d) requires two context pointers, one is of 'c', one another is of 'main'. But it is disallowed. So, the original code should be an error in my opinion.
Comment #4 by andrej.mitrovich — 2013-01-11T08:12:35Z
https://github.com/D-Programming-Language/dmd/pull/1466 D2 only. But D1 is officially deprecated, so what happens next? Will walter merge it into D1? I'll bring the popcorn!
Comment #5 by github-bugzilla — 2013-01-13T17:08:08Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/2e20e68eae3473b514d7cfa0275afa704c6990df Fixes Issue 8742 - ICE on anon class derived from nested class. https://github.com/D-Programming-Language/dmd/commit/c55d4ef45989574dddaa32f2e174bf5c5d0da90b Merge pull request #1466 from AndrejMitrovic/Fix8742 Issue 8742 - ICE on anon class derived from nested class.