mirror of
https://github.com/apple/swift.git
synced 2026-10-28 21:15:56 +01:00
This change restores pre-6.3 operator overload selection behavior. The same is done for cases when candidate matches all of the requirements placed on the generic parameter and optional injections because operators historically favored exact/subtype matches in concrete overloads above all else.
34 lines
1.7 KiB
Swift
34 lines
1.7 KiB
Swift
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
|
|
|
|
func identity<T>(_ t: T) -> T { return t }
|
|
|
|
extension Error where Self: Equatable {
|
|
// CHECK-LABEL: sil hidden [ossa] @$ss5ErrorP28operator_generics_vs_erasureSQRzrlE6equalsySbsAA_pF
|
|
// CHECK: // function_ref static Error.== infix(_:_:)
|
|
// CHECK: {{.*}} = function_ref @$ss5ErrorP28operator_generics_vs_erasureE2eeoiySbx_sAA_ptFZ
|
|
// CHECK: } // end sil function '$ss5ErrorP28operator_generics_vs_erasureSQRzrlE6equalsySbsAA_pF'
|
|
func equals(_ other: any Error) -> Bool {
|
|
other == self
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$ss5ErrorP28operator_generics_vs_erasureSQRzrlE14equalsWithCastySbsAA_pFSbxXEfU_
|
|
// CHECK: {{.*}} = witness_method $Self, #Equatable."==" : <Self where Self : Equatable, Self : ~Copyable, Self : ~Escapable> (Self.Type) -> (borrowing Self, borrowing Self) -> Bool
|
|
// CHECK: } // end sil function '$ss5ErrorP28operator_generics_vs_erasureSQRzrlE14equalsWithCastySbsAA_pFSbxXEfU_'
|
|
func equalsWithCast(_ other: any Error) -> Bool {
|
|
(other as? Self).map { $0 == self } ?? false
|
|
}
|
|
|
|
// CHECK-LABEL: sil private [ossa] @$ss5ErrorP28operator_generics_vs_erasureSQRzrlE18equalsWithIdentityySbsAA_pFSbxXEfU_
|
|
// CHECK: {{.*}} = witness_method $Self, #Equatable."==" : <Self where Self : Equatable, Self : ~Copyable, Self : ~Escapable> (Self.Type) -> (borrowing Self, borrowing Self) -> Bool
|
|
// CHECK: } // end sil function '$ss5ErrorP28operator_generics_vs_erasureSQRzrlE18equalsWithIdentityySbsAA_pFSbxXEfU_'
|
|
func equalsWithIdentity(_ other: any Error) -> Bool {
|
|
(other as? Self).map { $0 == identity(self) } ?? false
|
|
}
|
|
}
|
|
|
|
extension Error {
|
|
static func == (lhs: Self, rhs: any Error) -> Bool {
|
|
false
|
|
}
|
|
}
|