Bug 5679 – Type aliasing "this" from an access function defined in base class confuses the compiler about the type of objects
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2011-03-01T17:58:00Z
Last change time
2012-12-04T18:29:40Z
Keywords
pull, rejects-valid
Assigned to
nobody
Creator
puneet
Comments
Comment #0 by puneet — 2011-03-01T17:58:45Z
Type aliasing "this" from an access function defined in base class
confuses the compiler about the type of objects. Please see the
reduced test case that I have appended below. I am using dmd2
version 2.052 on a Linux box.
//// file alias_test.d
import std.stdio;
class Foo {
public int f = 42;
public void print() {
writeln(f);
}
}
class Base {
Foo foo;
@property protected final getFoo() {
if(foo is null) foo = new Foo();
return foo;
}
}
class Derived: public Base {
alias getFoo this;
}
void main() {
Derived[] dl;
Derived d = new Derived();
d.print(); // prints 42
writeln("Type of d1 is: ",
typeid(typeof(d))); // prints Type of d1 is: alias_test.Derived
dl ~= d; // Error: cannot append type alias_test.Base to type Derived[]
}
Comment #1 by lovelydear — 2012-04-22T23:38:39Z
After changing
class Derived: public Base {
by
class Derived: Base {
in line 15 to remove the deprecation error, the sample compiles and runs fine on 2.059.
Comment #2 by k.hara.pg — 2012-06-01T00:49:34Z
(In reply to comment #1)
> After changing
> class Derived: public Base {
> by
> class Derived: Base {
> in line 15 to remove the deprecation error, the sample compiles and runs fine
> on 2.059.
This issue was unintentionally fixed in 2.059, but appears in 2.060head again.
https://github.com/D-Programming-Language/dmd/pull/972
Comment #3 by github-bugzilla — 2012-11-19T23:18:44Z