Bug 22872 – __FUNCTION__ with opApply gives name of generated delegate instead of enclosing function

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

Comments

Comment #0 by snarwin+bugzilla — 2022-03-11T14:19:28Z
As of DMD 2.099.0, the following program fails to compile: --- module example; 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(__FUNCTION__ == "example.main"); } foreach (x; HasOpApply()) { // error static assert(__FUNCTION__ == "example.main"); } } --- The error is: --- example.d(23): Error: static assert: `"example.main.__foreachbody4" == "example.main"` is false --- This happens because __FUNCTION__ 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:27Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20067 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB