Parameterized Extensions

What is the plan for overlap detection? I looked at the PR and I don't see anything additional there for detecting overlap. For instance, if we have

struct S<A> { ... }
struct X { ... }
protocol PT { ... }
protocol PS { func f() }

extension<T : PT> S : PS where A == T { func f() { print("Generic") } }
extension         S : PS where A == X { func f() { print("Specialized") } }
extension X : PT { ... }

let s : S<X> = ...
s.f()
  1. What are the semantics of this? Do they depend on which modules the different declarations are in?
  2. Do we provide an error or warning about the ambiguity?
  3. Do we have syntax that lets the user manually pick which one they want?

This problem is already present with the existence of conditional conformances, and I am afraid by adding more ways of writing them (in this case, making equality constraints available, not just conformance constraints), we might exacerbate the issue. It seems even more of a problem with the "Future Directions" part where you allow blanket extensions over any generic type, because that can overlap with anything else (you can look at Haskell's OverlappingInstances extension, for example of the headaches this can cause). For now, at least we have one level of nesting in the extended type (e.g. S or Array or Pair) which makes it somewhat less likely.

3 Likes