[Issue 22870] New: __traits(parent) with opApply returns generated delegate instead of lexical parent
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Mar 11 14:15:37 UTC 2022
https://issues.dlang.org/show_bug.cgi?id=22870
Issue ID: 22870
Summary: __traits(parent) with opApply returns generated
delegate instead of lexical parent
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: normal
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: snarwin+bugzilla at gmail.com
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.
--
More information about the Digitalmars-d-bugs
mailing list