Files
swift-mirror/test/Constraints/ambiguity_diagnostics.swift
Pavel Yaskevich f12e24e85c [Diagnostics] Skip overloaded locations where all solutions have the same type
If there are multiple overloads, let's skip locations that produce
the same type across all of the solutions, such location is most
likely a consequence of ambiguity and not its source.

Resolves: rdar://109245375
2023-05-20 12:08:54 -07:00

51 lines
1.4 KiB
Swift

// RUN: %target-typecheck-verify-swift -swift-version 5 -disable-availability-checking
protocol View {
}
extension View {
func title<S>(_ title: S) -> some View where S : StringProtocol {
EmptyView()
}
func title(_ titleKey: LocalizedString) -> some View {
EmptyView()
}
}
extension View {
func background<T: ShapeStyle>(_: T) -> some View {
EmptyView()
}
}
struct EmptyView : View {}
struct Text : View {
init(_: String) {}
}
protocol ShapeStyle {
}
struct AnyShapeStyle : ShapeStyle {}
struct AnyGradient : ShapeStyle {}
struct LocalizedString : ExpressibleByStringLiteral, ExpressibleByExtendedGraphemeClusterLiteral {
init(extendedGraphemeClusterLiteral value: String) {}
init(stringLiteral: String) {}
}
func test() {
func __findValue(_: String, fallback: LocalizedString) -> LocalizedString { fatalError() }
func __findValue<T: ExpressibleByStringLiteral>(_: String, fallback: T) -> T { fatalError() }
func __findValue<T: ExpressibleByExtendedGraphemeClusterLiteral>(_: String, fallback: T) -> T { fatalError() }
func ambiguitySource() -> AnyShapeStyle { fatalError() } // expected-note {{found this candidate}}
func ambiguitySource() -> AnyGradient { fatalError() } // expected-note {{found this candidate}}
Text("Test")
.title(__findValue("someKey", fallback: "<unknown>"))
.background(ambiguitySource()) // expected-error {{ambiguous use of 'ambiguitySource()'}}
}