Skip to content
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

[SR-1841] QoI: Warn when shadowing generic type parameters #44450

Closed
atrick opened this issue Jun 20, 2016 · 0 comments
Closed

[SR-1841] QoI: Warn when shadowing generic type parameters #44450

atrick opened this issue Jun 20, 2016 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@atrick
Copy link
Member

atrick commented Jun 20, 2016

Previous ID SR-1841
Radar None
Original Reporter @atrick
Type Bug
Status Resolved
Resolution Duplicate
Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: a320ae5fc56b6d10b32756426b84493a

duplicates:

  • SR-1420 Provide compiler warning when shadowing generic type

relates to:

  • SR-8524 Shadowing in protocols leads to difficult to find bugs

Issue Description:

Is it normal to want to shadow generic type parameter names? If not, can we make it a compiler warning?

I recently helped someone with Swift who was confused by code like this:

struct Foo<T: Hashable> {
var t: T
func foo<T>() -> Int { return t.hashValue }
}
t.swift:3:12: error: generic parameter 'T' is not used in function signature
func foo<T>() -> Int { return t.hashValue }
^

The error message was unhelpful to them. They didn't realize that they were shadowing the class's generic parameter.

We only need a warning here that would show up before any subsequent diagnostics. Since a warning doesn't break code, I don't know that this needs to go through evolution.

<rdar://problem/26899805> QoI Warn when shadowing generic type parameters

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant