A proper WAT moment

John Colvin john.loughran.colvin at gmail.com
Tue Oct 15 07:06:35 UTC 2019


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. Reduced version:
>
> struct S
> {
>     int a;
>     int e() @property { return a; }
> }
>
> void foo(S s)
> {
>     pragma(msg, __LINE__, " ", __traits(compiles, S.e)); // 
> true (???)
>     S.e; // Error: need `this` for `e` of type `@property int()`
> }
>
> struct C
> {
>     void foo(S s)
>     {
>         pragma(msg, __LINE__, " ", __traits(compiles, S.e)); // 
> false
>         S.e; // Error: `this` for `e` needs to be type `S` not 
> type `C`
>     }
> }
>
> 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.


More information about the Digitalmars-d-learn mailing list