Skip to content

fix issue 22584: upgrade foreach variable shadowing from deprecation to error#22677

Open
Utkal059 wants to merge 2 commits intodlang:masterfrom
Utkal059:my-first-contribution
Open

fix issue 22584: upgrade foreach variable shadowing from deprecation to error#22677
Utkal059 wants to merge 2 commits intodlang:masterfrom
Utkal059:my-first-contribution

Conversation

@Utkal059
Copy link

@Utkal059 Utkal059 commented Mar 1, 2026

Fixes Issue 22584

Hi, this is my first contribution to DMD.

While going through open issues I noticed that foreach variable
shadowing was still showing a deprecation warning even though
the deprecation period has already ended.

What I changed:
In expressionsem.d I changed the diagnostic from deprecation()
to error() for foreach variables that shadow outer scope symbols.

Why I made this change:
Since the deprecation period is over this should now be a hard
error. It also helps catch subtle bugs where a foreach variable
accidentally hides an outer variable without the programmer noticing.

Testing:
I confirmed that the correct error message appears when
shadowing occurs in a foreach loop.

Closes: https://issues.dlang.org/show_bug.cgi?id=22584

@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @Utkal059! 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

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

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#22677"

@Utkal059 Utkal059 force-pushed the my-first-contribution branch from 8e0e8c8 to f1025e4 Compare March 1, 2026 21:46
@Utkal059 Utkal059 force-pushed the my-first-contribution branch from f1025e4 to 8f57389 Compare March 1, 2026 21:48
Copy link
Contributor

@thewilsonator thewilsonator left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you will need to have a chanelog entry for this. cc @dkorpel should this be done at all or done via editions?

@Herringway
Copy link
Contributor

Herringway commented Mar 1, 2026

You linked to an unrelated bugzilla issue, I think you meant github issue #22584?

EDIT: I think you can remove the -de switch from the REQUIRED_ARGS comment as well.

@Utkal059
Copy link
Author

Utkal059 commented Mar 3, 2026

I've fixed the trailing whitespace issue.
Could a maintainer please approve the workflows? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants