Static member lookup with multiple generic contexts

In the nightly compiler, the following code which exercises swift-evolution/ at main · apple/swift-evolution · GitHub doesn't work:

protocol Foo { }
struct Bar: Foo { }
extension Foo where Self == Bar {
  static func bar(_ foo: Foo) -> Self {  fatalError() }
  static var baz: Self { fatalError() }
func foo() {
  let _: Foo = .baz // Works
  let _: Foo = .bar(Bar.baz) // Works
  let _: Foo = .bar(.baz) // "Type of expression is ambiguous without more context"

Is this is a bug, a limitation of the current implementation, or something that explicitly won't be supported? @xedin

This is expected because argument to bar is existential type of Foo which can't reference a static member baz, you need to change declaration to func bar<T: Foo>(_ foo: T) -> Self to make it work.


Ahh, right you are! Thanks for the quick response!

No worries, happy to help!