enum E<T> {
func ƒ<T>(_: T) { // Generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
func ƒ<T>(_: T) { } // Generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
}
}
Sometimes a shadowed same name is exactly the right name. The right thing to do would be to be able to refer to outer scope somehow. But instead, we just have to give up on correct naming?
Today's example: W. This is what I see from great programmers, frequently. A letter. What happens when W is in W? It's disheartening.
The right thing to do is a challenging design and implementation problem, and as you've discovered, we're very busy with many other challenging design and implementation problems. We cannot solve all of these problems at once. In the meantime, folks who are less experienced with generic code are stubbing their toes on shadowed type parameters, and resilient libraries that use shadowed type parameters produce invalid Swift interfaces, leading to cryptic errors when trying to rebuild a module from Swift interface or using one of the resulting APIs (see Emit a warning when type parameters are shadowed. · Issue #62767 · apple/swift · GitHub). I strongly believe that the right thing to do is also to prevent people from stumbling into these corners of the language until we have a better solution.