This is consistent with the way contextual lookup works when type variables are bound in other positions. For example:
protocol P {}
struct Foo: P {}
struct Bar: P {}
struct Q<T: P> {
static var foo: Q<Foo> {
print("foo via P")
return Q<Foo>()
}
}
extension Q where T == Foo {
static var foo: Q<Bar> {
print("foo via Foo")
return Q<Bar>()
}
}
extension Q where T == Bar {
var bar: Q<Bar> { Q<Bar>() }
var baz: Q<Foo> { Q<Foo>() }
}
func test<T: P>(_: Q<T>) {}
test(.foo.bar.baz)
also prints foo via Foo
. Encouraging and/or requiring static members found in a top-level generic context to use Self
same type constraints would nonetheless reduce the potential for this behavior.
The core team would like the proposal to acknowledge the issue of concrete type namespace pollution, and include this in its examples as the encouraged way of avoiding that problem. We should also consider whether such a constraint ought to be required to find members in generic context.