Files
swift-mirror/test/Constraints/bidirectional_conversions.swift
Slava Pestov f3e6b4ceda Sema: Disambiguate some more bidirectional conversions
This fixes an ambiguity introduced by the stdlib change in
0f99458900.

Since (borrowing T) -> () and (T) -> () both convert to
each other, we could end up with ambiguous solutions where
neither one was better than the other. Generalize the
existing trick we use for labeled vs unlabeled tuples to
also strip off ownership specifiers and @convention(...)
from function types. This fixes the regression, as well
an existing FIXME in a test I added a while ago where
the same problem arises with @convention(block).
2025-12-09 18:31:59 -05:00

80 lines
1.3 KiB
Swift

// RUN: %target-typecheck-verify-swift
/////////////
struct G<T> {
var t: T
}
func foo1(x: (x: Int, y: Int)?, y: (Int, Int)) -> G<(x: Int, y: Int)> {
let g = G(t: x ?? y)
return g
}
func foo2(x: (Int, Int)?, y: (x: Int, y: Int)) -> G<(Int, Int)> {
let g = G(t: x ?? y)
return g
}
/////////////
func id<T>(_: T) -> T {}
func bar1(x: (x: Int, y: Int)) {
func f(_: (Int, Int)) {}
f(id(x))
}
func bar2(x: (Int, Int)) {
func f(_: (x: Int, y: Int)) {}
f(id(x))
}
/////////////
func unwrap<T>(_: T?) -> T {}
func baz1(x: (x: Int, y: Int)?) {
func f(_: (Int, Int)) {}
f(unwrap(x))
}
func baz2(x: (Int, Int)?) {
func f(_: (x: Int, y: Int)) {}
f(unwrap(x))
}
/////////////
func borrowingFn(fn: @escaping (borrowing AnyObject) -> ()) -> (AnyObject) -> () {
return id(id(fn))
}
/////////////
infix operator <+
infix operator >+
protocol P {
static func <+ (lhs: borrowing Self, rhs: borrowing Self)
static func >+ (lhs: borrowing Self, rhs: borrowing Self)
}
extension P {
static func >+ (lhs: borrowing Self, rhs: borrowing Self) {}
}
struct S: P {
static func <+ (lhs: Self, rhs: Self) {}
}
let _: (S, S) -> () = false ? (<+) : (>+)
/////////////
struct MyString: Comparable {
static func < (lhs: Self, rhs: Self) -> Bool { fatalError() }
}
let _: (MyString, MyString) -> Bool = false ? (<) : (>)