Files
swift-mirror/test/Sema/availability_with_overloading.swift
Pavel Yaskevich 71753f3ca6 [ConstraintSystem] Rank contextually unavailable overloads lower than other choices (#29921)
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
2020-02-19 13:13:53 -05:00

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
}