Bug 22870 – __traits(parent) with opApply returns generated delegate instead of lexical parent

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-03-11T14:15:37Z
Last change time
2024-12-13T19:21:25Z
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#20066 →

Comments

Comment #0 by snarwin+bugzilla — 2022-03-11T14:15:37Z
As of DMD 2.099.0, the following program fails to compile: --- struct HasOpApply { int opApply(int delegate(int) dg) { if (int result = dg(0)) return result; return 0; } } void main() { foreach (x; 0 .. 1) { // ok static assert(__traits(identifier, __traits(parent, {})) == "main"); } foreach (x; HasOpApply()) { // error static assert(__traits(identifier, __traits(parent, {})) == "main"); } } --- The error is: --- onlineapp.d(21): Error: static assert: `"__foreachbody5" == "main"` is false --- This happens because __traits(parent) is evaluated after the compiler has transformed the foreach loop into a call to HasOpApply.opApply.
Comment #1 by robert.schadek — 2024-12-13T19:21:25Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20066 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB