[Issue 5679] New: Type aliasing "this" from an access function defined in base class confuses the compiler about the type of objects

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Mar 1 18:01:36 PST 2011


http://d.puremagic.com/issues/show_bug.cgi?id=5679

           Summary: Type aliasing "this" from an access function defined
                    in base class confuses the compiler about the type of
                    objects
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: puneet at coverify.org


--- Comment #0 from Puneet Goel <puneet at coverify.org> 2011-03-01 17:58:45 PST ---
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[]
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list