dmd icon indicating copy to clipboard operation
dmd copied to clipboard

Fix issue 18439: Remove attributes applied to hidden lambda in static foreach

Open looked-at-me opened this issue 4 years ago • 6 comments

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.

looked-at-me avatar Mar 01 '20 07:03 looked-at-me

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: and Returns:)

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"

dlang-bot avatar Mar 01 '20 07:03 dlang-bot

If stable is targeted it could still be part of the 2.091 release.

wilzbach avatar Mar 01 '20 08:03 wilzbach

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.

tgehr avatar Mar 01 '20 13:03 tgehr

https://github.com/dlang/dmd/pull/9922

tgehr avatar Mar 01 '20 13:03 tgehr

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.

looked-at-me avatar Mar 02 '20 02:03 looked-at-me

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
}

BorisCarvajal avatar Nov 05 '20 00:11 BorisCarvajal