[Issue 23761] New: Trait getOverloads does not retain "this" reference when used with instance

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Mar 6 21:37:20 UTC 2023


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 at puremagic.com
          Reporter: m.bierlee at 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

--


More information about the Digitalmars-d-bugs mailing list