You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
Additional Detail from JIRA
md5: a320ae5fc56b6d10b32756426b84493a
duplicates:
relates to:
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
The text was updated successfully, but these errors were encountered: