mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Introduce an algorithm to canonicalize and minimize same-type constraints. The algorithm itself computes the equivalence classes that would exist if all explicitly-provided same-type constraints are ignored, and then forms a minimal, canonical set of explicit same-type constraints to reform the actual equivalence class known to the type checker. This should eliminate a number of problems we've seen with inconsistently-chosen same-type constraints affecting canonicalization.
25 lines
722 B
Swift
25 lines
722 B
Swift
// RUN: %target-typecheck-verify-swift -swift-version 3
|
|
|
|
protocol P {
|
|
associatedtype A
|
|
associatedtype B
|
|
|
|
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B // expected-warning{{adding constraint 'Self.A == Self.B' on 'Self' via instance method requirement 'f' is deprecated}}
|
|
// expected-note@-1{{protocol requires function 'f' with type '<T> (T) -> ()'; do you want to add a stub?}}
|
|
}
|
|
|
|
extension P {
|
|
func f<T: P>(_: T) where T.A == Self.A, T.A == Self.B { } // expected-note{{candidate has non-matching type '<Self, T> (T) -> ()'}}
|
|
}
|
|
|
|
struct X : P { // expected-error{{type 'X' does not conform to protocol 'P'}}
|
|
typealias A = X
|
|
typealias B = Int
|
|
}
|
|
|
|
struct Y : P {
|
|
typealias A = Y
|
|
typealias B = Y
|
|
}
|
|
|