Bug 5365 – Regression (2.051) implicit conversions via alias this are broken

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-12-23T02:19:00Z
Last change time
2010-12-27T04:04:15Z
Assigned to
nobody
Creator
samukha

Comments

Comment #0 by samukha — 2010-12-23T02:19:35Z
The following compiles and runs correctly with dmd 2.050, but segfaults with dmd 2.051 interface IFactory { void foo(); } class A { protected static class Factory : IFactory { void foo() { } } this() { _factory = createFactory(); } protected IFactory createFactory() { return new Factory; } private IFactory _factory; @property final IFactory factory() { return _factory; } alias factory this; } void main() { IFactory f = new A; f.foo(); // segfault } Critical for QtD.
Comment #1 by bearophile_hugs — 2010-12-23T02:44:22Z
It works with DMD 2.051 if I replace this line of the main(): IFactory f = new A; With: A f = new A;
Comment #2 by samukha — 2010-12-23T03:51:52Z
(In reply to comment #1) > It works with DMD 2.051 if I replace this line of the main(): > IFactory f = new A; > > With: > A f = new A; We still need the implicit cast to work correctly. For example, we cannot pass an A to a function taking an IFactory: void bar(IFactory f) { f.foo(); // segfault } auto a = new A; bar(a); Here is a simplified test-case: class B { } class A { B _b; this() { _b = new B; } B b() { return _b; } alias b this; } void main() { auto a = new A; B b = a; // b is null assert(a._b is b); // fails }
Comment #3 by samukha — 2010-12-23T05:26:06Z
Changed subject to something arguably more relevant.
Comment #4 by bugzilla — 2010-12-26T18:32:51Z
This was broken by the fix for 5094. The fix for 5094 was good, it just exposed another problem that needed fixing. http://www.dsource.org/projects/dmd/changeset/818 QtD is an important project for D; please consider trying out the beta compilers as they come out to head off regresssions in the future.
Comment #5 by samukha — 2010-12-27T04:04:15Z
(In reply to comment #4) > This was broken by the fix for 5094. The fix for 5094 was good, it just exposed > another problem that needed fixing. > > http://www.dsource.org/projects/dmd/changeset/818 This fixes the issue. Thanks! There is yet another issue that prevents us from implementing multiple inheritance in a satisfactory way http://d.puremagic.com/issues/show_bug.cgi?id=5380 > > QtD is an important project for D; please consider trying out the beta > compilers as they come out to head off regresssions in the future. We usually do but not this particular version.