mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Currently constraint solver is only capable of detecting universally unavailable overloads but that's insufficient because it's still possible to pick a contextually unavailable overload choice which could be better than e.g. generic overload, or one with defaulted arguments, marked as disfavored etc. Let's introduce `ConstraintSystem::isDeclUnavailable` which supports both universal and contextual unavailability and allow constraint solver to rank all unavailable overload choices lower than any other possible choice(s). Resolves: rdar://problem/59056638
41 lines
961 B
Swift
41 lines
961 B
Swift
// RUN: %target-swift-frontend -emit-sil -verify %s | %FileCheck %s
|
|
|
|
// REQUIRES: OS=macosx
|
|
|
|
protocol View {}
|
|
|
|
extension View {
|
|
@_disfavoredOverload
|
|
func frame(width: Double?, height: Double? = nil) {
|
|
}
|
|
}
|
|
|
|
@available(macOS 999, *)
|
|
extension View {
|
|
func frame(width: Double?) {
|
|
}
|
|
}
|
|
|
|
func test_disfavored_vs_unavailable(_ view: View) {
|
|
view.frame(width: 100) // Ok
|
|
// CHECK: function_ref @$s29availability_with_overloading4ViewPAAE5frame5width6heightySdSg_AGtF
|
|
}
|
|
|
|
struct S {
|
|
func foo<T: StringProtocol>(_: T) {}
|
|
func bar(_: Int, _: Int = 0) {}
|
|
}
|
|
|
|
@available(macOS 999, *)
|
|
extension S {
|
|
func foo(_: String) {}
|
|
func bar(_: Int) {}
|
|
}
|
|
|
|
func test_generic_vs_unavailable(_ s: S) {
|
|
s.foo("") // Ok (picks available generic overload)
|
|
// CHECK: function_ref @$s29availability_with_overloading1SV3fooyyxSyRzlF
|
|
s.bar(42) // Ok (picks overload with defaulted argument)
|
|
// CHECK: function_ref @$s29availability_with_overloading1SV3baryySi_SitF
|
|
}
|