www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 23761] New: Trait getOverloads does not retain "this"

https://issues.dlang.org/show_bug.cgi?id=23761

          Issue ID: 23761
           Summary: Trait getOverloads does not retain "this" reference
                    when used with instance
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Windows
            Status: NEW
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: m.bierlee lostmoment.com

With the following code:

-----
class PrincipleClass {
    public void theMethod() {

    }
}

class SecondaryClass {
    public void doIt() {
        PrincipleClass instance = new PrincipleClass();
        foreach (overload; __traits(getOverloads, instance, "theMethod")) {
            overload();
        }
    }
}

void main() {
    new SecondaryClass().doIt();
}
-----

I get the following compilation error:

-----
 Error: `this` for `theMethod` needs to be type `PrincipleClass` not type
`app.SecondaryClass`
Error D:\DLang\dmd2\windows\bin64\dmd.exe failed with exit code 1.
-----

It seems that the overload does not retain a reference to the instance it came
from. Using it as it is now seems to be useless, that is: the 'this' reference
of the method being the caller's.

DMD: DMD64 D Compiler v2.102.2-dirty

--
Mar 06 2023