www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6570] New: 'this' silently passes from one object to another

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6570

           Summary: 'this' silently passes from one object to another
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: alienballance gmail.com



03:42:57 PDT ---
<code>
import std.stdio;

class T {
    abstract string type() {
        return "T";
    }
}

class T2 : T {
    override string type() {
        return "T2";
    }
    void test(T)() {
        writeln(T.type);
    }
}

void main() {
    (new T2).test!T();
}
</code>
<output>T2</output>
type() isn't static method so AFAIK it shouldn't be possible to call it from
test(). Instead of that, call is possible, and local 'this' is used.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 29 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6570


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |INVALID



10:28:46 PST ---
I don't know why 'T2' was in output, it should be 'T' (and it is now).

As for why it works: this is used to pick a specific override in some base
class, e.g.:

class A
{
    void test() { }
}

class B : A
{
    override void test() { }
}

class C : B
{
    override void test() { A.test(); }
}

If you use 'super.test()' you would end up calling B.test instead of A.test.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 02 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6570





 I don't know why 'T2' was in output, it should be 'T' (and it is now).
 
 As for why it works: this is used to pick a specific override in some base
 class, e.g.:
 
 class A
 {
     void test() { }
 }
 
 class B : A
 {
     override void test() { }
 }
 
 class C : B
 {
     override void test() { A.test(); }
 }
 
 If you use 'super.test()' you would end up calling B.test instead of A.test.
That is bug 8809 and was fixed in 2.061head. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Dec 02 2012