Bug 10697 – Syntactically Incorrect Alias This Causes Object to Conflict with Itself

Status
RESOLVED
Resolution
INVALID
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-07-22T10:35:52Z
Last change time
2018-10-23T12:34:06Z
Assigned to
No Owner
Creator
Meta

Comments

Comment #0 by monkeyworks12 — 2013-07-22T10:35:52Z
import std.stdio; struct Test1 { int i; } struct Test2 { Test1 test1; alias this test1; } void main() { Test2 test2; writeln(test2.i); } /d995/f66.d(11): Error: alias f66.Test2.test1 conflicts with variable f66.Test2.test1 at /d995/f66.d(10) This also fails on GDC 2.060 and LDC 2.060, and whatever version of git HEAD dpaste is using. http://dpaste.dzfl.pl/5f8bb3f4
Comment #1 by razvan.nitu1305 — 2018-10-23T12:34:06Z
That's not a syntactically incorrect alias this. That is a an alias called test1 to typeof(this). Renaming test1 to something else makes the code compile (with a deprecation warning, at the time of the creation of this post, that **this** cannot be used as a type, but that's something different). The compiler cannot simply assume that you were trying to write an alias this since you could be trying to write an alias to the type of this. Closing as invalid.