[Issue 18104] New: Alias example compiles where it states that it should be illegal
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Tue Dec 19 11:05:22 UTC 2017
https://issues.dlang.org/show_bug.cgi?id=18104
Issue ID: 18104
Summary: Alias example compiles where it states that it should
be illegal
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: trivial
Priority: P1
Component: dlang.org
Assignee: nobody at puremagic.com
Reporter: michael at toohuman.io
Thread located here:
https://forum.dlang.org/thread/oucxcxaepcjgnmbetbll@forum.dlang.org
This thread is referring to an example used in the documentation regarding
Alias, specifically, the last example:
Aliases cannot be used for expressions:
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
This code compiles fine, most likely related to i being a static member, you
can go on to change i through a or b. The following example indicates where an
error occurs:
import std.stdio;
struct S
{
static int i;
int j;
}
S s;
void main(string[] args)
{
alias a = s.i;
a = 1; // OK
alias b = S.i;
b = 2; // OK
alias c = s.j;
c = 3; // Error: need 'this' for 'j' of type 'int'
alias d = S.j;
d = 4; // Error: need 'this' for 'j' of type 'int'
}
Using DMD64 D Compiler v2.077.1
--
More information about the Digitalmars-d-bugs
mailing list