Bug 3393 – illegal to refer to 'this' implicitly or explicitly

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2009-10-13T07:44:56Z
Last change time
2024-12-13T17:50:46Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
anonymous4
Blocks
4571
Moved to GitHub: dmd#17508 →

Comments

Comment #0 by dfj1esp02 — 2009-10-13T07:44:56Z
Spec reads: 3. It is illegal to refer to this implicitly or explicitly prior to making a constructor call. Although it's allowed. --- class A { int a; this(){ M(); this(1); } this(int b){ a=b; } void M(){ writeln("A.M"); } } class B:A { int b; this(){ M(); super(); b=5; } override void M(){ writeln("B.M ",b); } } int main() { auto b=new B(); b.M(); return 0; } --- output is --- B.M 0 B.M 0 B.M 5 --- We see how virtual method is called prior to constructor calls and overridden method from derived class is called from the constructor of the base class (called on not yet constructed object).
Comment #1 by nfxjfg — 2010-10-16T12:44:26Z
Same problem with D1. Also see bug 5056.
Comment #2 by bugzilla — 2012-01-23T01:31:18Z
Compiler bug, not a spec issue.
Comment #3 by robert.schadek — 2024-12-13T17:50:46Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17508 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB