dmd/compiler/test/fail_compilation/test24353.d
royalpinto007 f5f7baeb19 fix Bugzilla 24353 - add mutability check for foreach with opApply
Signed-off-by: royalpinto007 <royalpinto007@gmail.com>
2024-11-17 07:44:19 +08:00

24 lines
440 B
D

// https://issues.dlang.org/show_bug.cgi?id=24353
/**
TEST_OUTPUT:
---
fail_compilation/test24353.d(23): Error: mutable method `test24353.S.opApply` is not callable using a `const` object
fail_compilation/test24353.d(14): Consider adding `const` or `inout` here
---
*/
struct S
{
int opApply(int delegate(int) dg)
{
return 0;
}
}
void example()
{
const S s;
foreach (e; s) {} // Error expected here
}