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
Commits pushed to master at https://github.com/dlang/dlang.org https://github.com/dlang/dlang.org/commit/9ad4c395470befec8293593fc8dfbdc906cfb56f Fix Issue 18104: improve example showing that aliases cannot be used for expressions https://github.com/dlang/dlang.org/commit/92ff7aa56b7897d8545fe4f2882cc3165c338d3e Merge pull request #2457 from ghost91-/fix-issue-18104 Fix Issue 18104: improve example showing that aliases cannot be used … merged-on-behalf-of: Petar Kirov <[email protected]>