Alias example should supposedly be illegal, but runs fine
Mike Franklin
slavo5150 at yahoo.com
Tue Dec 19 01:30:07 UTC 2017
On Monday, 18 December 2017 at 23:44:46 UTC, Michael wrote:
> I have been looking at the following example found right at the
> end of the section here:
> https://dlang.org/spec/declaration.html#alias
>
> struct S { static int i; }
> S s;
>
> alias a = s.i; // illegal, s.i is an expression
> alias b = S.i; // ok
> b = 4; // sets S.i to 4
>
> and it runs fine to me, including if I add:
I think the example is wrong. Consider this:
----
import std.stdio;
struct S
{
static int i;
int j;
}
S s;
void main()
{
s.i = 1;
s.j = 2;
writeln(s.i); // OK: Static symbols can be used through
instances
writeln(S.i); // OK: Static symbols can be used through types
writeln(s.j); // OK: Instance symbols can be used through
instances
//writeln(S.j); // Error: Instance symbols cannot be used
through types.
}
----
https://run.dlang.io/is/eppwuf
Please file a bug report at http://issues.dlang.org/
Mike
More information about the Digitalmars-d-learn
mailing list