[Pitch] Associated Type Disambiguation

The right solution is to reject substitution maps with incompatible conformances at the call site, eg:

protocol P {
  associatedtype A
}

protocol Q {
  associatedtype A
}

struct G<T> {}

extension G: P where T: Hashable {
  typealias A = Bool
}

extension G: Q where T: Comparable {
  typealias A = Float
}

func f<T: P & Q>(_: T) {}

// all declarations up until here are good!

// but Int conforms to both Hashable and Comparable:

f(G<Int>())  // so an error must be diagnosed here

This is a known issue that I'd like to fix some day. However, it's a fairly involved fix that requires a good understanding of Part 4 in https://download.swift.org/docs/assets/generics.pdf, as well as the requirement minimization algorithm, which is not even documented yet.

1 Like