Skip to content

Sema: Ban shadowing generic parameters from outer scopes [5.9] #65430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

slavapestov
Copy link
Contributor

  • Description: Emit a warning (in -swift-version 5) or an error (in -swift-version 6) if you re-declare a generic parameter with the same name in a nested scope. Code like that is usually indicative of programmer error, and does not round-trip through module interface files since there is no source syntax to refer to an outer generic parameter. We've had to debug some weird issues which turned out to be caused by this.
  • Risk: The new check might introduce a compiler crash or something, but it's a slightly generalized form of the old check (which prohibited re-declaring a generic parameter with the same name within a single scope only).
  • Radar: rdar://problem/108385980
  • Reviewed by: @xedin

Code like that is usually indicative of programmer error, and does not
round-trip through module interface files since there is no source
syntax to refer to an outer generic parameter.

For source compatibility this is a warning, but becomes an error with
-swift-version 6.

Fixes rdar://problem/108385980 and swiftlang#62767.
@slavapestov slavapestov requested a review from a team as a code owner April 26, 2023 02:24
@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov slavapestov merged commit 46b5df0 into swiftlang:release/5.9 Apr 26, 2023
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks swift 5.9
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants