Bug 18104 – Alias example compiles where it states that it should be illegal
Status
RESOLVED
Resolution
FIXED
Severity
trivial
Priority
P1
Component
dlang.org
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2017-12-19T11:05:22Z
Last change time
2018-08-28T07:25:32Z
Keywords
bootcamp
Assigned to
No Owner
Creator
Michael
Comments
Comment #0 by michael — 2017-12-19T11:05:22Z
Thread located here: https://forum.dlang.org/thread/[email protected]
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
Comment #1 by github-bugzilla — 2018-08-28T07:25:31Z