A proper WAT moment

Simen Kjærås simen.kjaras at gmail.com
Tue Oct 15 09:34:41 UTC 2019


On Tuesday, 15 October 2019 at 07:06:35 UTC, John Colvin wrote:
> On Monday, 14 October 2019 at 19:45:11 UTC, Paul Backus wrote:
>> On Monday, 14 October 2019 at 17:00:56 UTC, John Colvin wrote:
>>> Different ability to access a property depending if I'm 
>>> inside something else when I look?
>>>
>>> [snip]
>>
>> You're attempting to call one of S's member functions without 
>> an instance of S to call it on.
[snip]
>> The real issue here is that the first `__traits(compiles)` 
>> check succeeds, even though the actual expression fails.
>
> And all the other ones in my example that access members 
> without an instance that also compile?
>
> There's something pretty strange about the rules here.

Yeah, Paul's wrong here - the struct is what messes things up 
here, though I don't understand why. Just putting the first 
function inside a struct cause the exact same issue:

struct S {
     int a;
     int e() @property { return a; }
}

pragma(msg, __LINE__, " ", __traits(compiles,__traits(getMember, 
S, "e")));

void fun() {
     pragma(msg, __LINE__, " ", 
__traits(compiles,__traits(getMember, S, "e")));
}

struct S2 {
     void fun() {
         pragma(msg, __LINE__, " ", 
__traits(compiles,__traits(getMember, S, "e")));
     }
}

Interestingly, the code does of course actually compile:

struct S3 {
     void fun() {
         alias a = __traits(getMember, S, "e");
     }
}


More information about the Digitalmars-d-learn mailing list