Let’s take this simplified example:
class Container<A> {
static func foo<A>(item: A) {
...
}
}
Xcode gives me a warning saying Generic parameter 'A' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
.
But in my particular case, shadowing the outer generic is exactly what I need to do.
The real problem comes when I want to call the method foo without specifying any generic type, so relying completely on Swift’s type inference, like:
Container.foo(item: 42)
Swift correctly infers foo’s A
type as an Int
, but gives me an error Generic parameter 'A' could not be inferred
because it still requires Container’s A
type.
Is there a way to “bypass” this and make Container
not require its generic given that it has been shadowed by the foo’s one?