A proper WAT moment
Jacob Carlborg
doob at me.com
Wed Oct 16 18:36:36 UTC 2019
On 2019-10-15 09:06, John Colvin wrote:
> 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.
The thing is that it should be possible to access a non-static member
without an instance because it's possible to manually construct a delegate:
class S
{
int a;
int e() @property { return a; }
}
void foo()
{
int function() f = &S.e; // this compiles
int delegate() dg;
S s;
dg.ptr = &s;
dg.funcptr = f;
}
struct C
{
void bar()
{
int function() f = &S.e; // this fails for some reason but
should compile
}
}
So the expression `S.e` should compile, because it can be part of a
large expression, i.e. `&S.e`, which should compile.
The strange thing is that it fails to compile inside `C`. But if `bar`
is changed to a static method it compiles again.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list