dmd
dmd copied to clipboard
Fix issue 18439: Remove attributes applied to hidden lambda in static foreach
I think someone said they were making a patch that'd "fix" this issue, but it has been close to a year now with no "fix" in sight and I keep bumping up against this bug. Would rather have a simple imperfect 5 line patch than let perfection be the enemy of sanity.
Thanks for your pull request and interest in making D better, @looked-at-me! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Please verify that your PR follows this checklist:
- My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
- My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
- I have provided a detailed rationale explaining my changes
- New or modified functions have Ddoc comments (with
Params:
andReturns:
)
Please see CONTRIBUTING.md for more information.
If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.
Bugzilla references
Auto-close | Bugzilla | Severity | Description |
---|---|---|---|
✓ | 18439 | major | Error: cannot use operator ~= in @nogc delegate 'main.test.__lambda1' |
Testing this PR locally
If you don't have a local development environment setup, you can use Digger to test this PR:
dub run digger -- build "master + dmd#10851"
If stable is targeted it could still be part of the 2.091 release.
Like I said last time, there should be a comment in the code that this is a temporary hack that will be removed once the mess with attributes is sorted out. I'm not opposed to temporarily pulling this, but I had explained how to fix this the proper way and that fix requires way fewer changes to the source code, so I don't really buy the 5-line-change argument.
https://github.com/dlang/dmd/pull/9922
Pure will be a bit more involved fix due to the hacky use of lambdas in the implementation and the way nested lambda's infer their purity. It'll just have to be @nogc
for now. The error message for pure is less cryptic.
The test case no longer triggers the error since v2.094 because numeric ranges no longer use CTFE,
but using opApply
(or a range interface) does it, of course.
@nogc:
struct S
{
int opApply(scope int delegate(int) dg) { return 0;}
}
void test() {
static foreach(i; S()) {} // @nogc
}