Bug 21475 – template 'this' parameter is incorrectly handled for 'alias this'

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2020-12-12T10:37:48Z
Last change time
2024-12-13T19:13:28Z
Assigned to
No Owner
Creator
Max Samukha
Moved to GitHub: dmd#19839 →

Comments

Comment #0 by maxsamukha — 2020-12-12T10:37:48Z
struct S { string rt; void _init(this T)() { rt = T); } } struct S2 { S s; alias s this; } void main() { S2 s2; s2._init; assert(s2.rt == "S2"); } T is incorrectly resolved to S, while it should be typeof(s2), which is S2.
Comment #1 by maxsamukha — 2020-12-12T10:39:10Z
(In reply to Max Samukha from comment #0) > struct S { > string rt; > void _init(this T)() { > rt = T); > } > } > > struct S2 { > S s; > alias s this; > } > > void main() { > S2 s2; > s2._init; > assert(s2.rt == "S2"); > } > > T is incorrectly resolved to S, while it should be typeof(s2), which is S2. Corrected test case: struct S { string rt; void _init(this T)() { rt = __traits(identifier, T); } } struct S2 { S s; alias s this; } void main() { S2 s2; s2._init; assert(s2.rt == "S2"); }
Comment #2 by robert.schadek — 2024-12-13T19:13:28Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19839 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB