Bug 12496 – __traits(parent, x) returns incorrect type

Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-03-30T22:45:55Z
Last change time
2017-12-18T22:57:51Z
Assigned to
No Owner
Creator
Mike Franklin
See also
https://issues.dlang.org/show_bug.cgi?id=13372

Comments

Comment #0 by slavo5150 — 2014-03-30T22:45:55Z
Consider the following code: /*********** mmio.d ************/ module mmio; mixin template HasValue(uint value) { static uint getValue() { return value; } } mixin template Parent() { final abstract class Child(uint value) { mixin HasValue!(value); } } /*********** test.d ************/ module test; import mmio; mixin Parent; alias Two = Child!(2); /*********** main.d ************/ import std.stdio; import test; void main() { writeln(__traits(parent, test.Two).stringof); writeln(__traits(parent, __traits(parent, test.Two)).stringof); readln(); } DMD 2.065 Output: Child!(2) Child!(2) GDC 4.8.2 20130725 Output: Child Child LDC 0.12.1 Output: Child Child Expected output: module test {the second `writeln` shouldn't compile since `test` has no parent} A couple of observations: 1. `Child` is not the parent of `test.Two`, `test` is the parent of `test.Two`. 2. If you believe `__traits(parent, test.Two)` is `Child`, `Child` should not be its own parent. If the template parameter on `Child` is removed, it returns the correct type.
Comment #1 by andrej.mitrovich — 2014-03-31T05:08:20Z
Seems similar to a bug Vladimir filed recently.
Comment #2 by slavo5150 — 2015-01-25T05:57:05Z
Possibly the same as Issue 13372
Comment #3 by slavo5150 — 2017-08-23T06:04:35Z
A better example: module test; import std.stdio; final abstract class T1 { final abstract class C(uint value) { static uint getValue() { return value; } } alias Child = C!2; } final abstract class T2 { final abstract class Child { static uint getValue() { return 2; } } } void main() { writeln(__traits(parent, T1.Child).stringof); // this should be T1 writeln(__traits(parent, T2.Child).stringof); // this should be, and is, T2 }
Comment #4 by slavo5150 — 2017-11-20T09:43:27Z
Comment #5 by github-bugzilla — 2017-11-26T23:09:09Z
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b74bb167d2bd49d47d01f0f19277b5441ade3afc Fix Issue 12496: __traits(parent, x) returns incorrect symbol https://github.com/dlang/dmd/commit/d94a080030193fb0514bc512265e18dfe4d973f0 Merge pull request #7097 from JinShil/fix_12496 Fix Issue 12496: __traits(parent, x) returns incorrect symbol merged-on-behalf-of: Mike <[email protected]>
Comment #6 by github-bugzilla — 2017-12-18T22:57:51Z
Commits pushed to stable at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/b74bb167d2bd49d47d01f0f19277b5441ade3afc Fix Issue 12496: __traits(parent, x) returns incorrect symbol https://github.com/dlang/dmd/commit/d94a080030193fb0514bc512265e18dfe4d973f0 Merge pull request #7097 from JinShil/fix_12496