From 2137e1bafd7b34d2be9ab5a7da29a6ec2fc362b3 Mon Sep 17 00:00:00 2001 From: Pavel Yaskevich Date: Thu, 8 Apr 2021 16:02:32 -0700 Subject: [PATCH] [TypeChecker] NFC: Add a test-case to test condition requirements interaction with transitive conformance checks --- test/Constraints/protocols.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/Constraints/protocols.swift b/test/Constraints/protocols.swift index eb5e22bfbac..bfca35ac6ac 100644 --- a/test/Constraints/protocols.swift +++ b/test/Constraints/protocols.swift @@ -454,3 +454,23 @@ func test_inference_through_implicit_conversion() { let _: UnsafePointer = test([C()]) // Ok - argument is implicitly converted to a pointer let _: AnyHashable = test(C()) // Ok - argument is implicitly converted to `AnyHashable` because it's Hashable } + +// Make sure that conformances transitively checked through implicit conversions work with conditional requirements +protocol TestCond {} + +extension Optional : TestCond where Wrapped == Int? {} + +func simple(_ x: T) -> T { x } + +func overloaded(_ x: T) -> T { x } +func overloaded(_ x: String) -> T { fatalError() } + +func overloaded_result() -> Int { 42 } +func overloaded_result() -> String { "" } + +func test_arg_conformance_with_conditional_reqs(i: Int) { + let _: Int?? = simple(i) + let _: Int?? = overloaded(i) + let _: Int?? = simple(overloaded_result()) + let _: Int?? = overloaded(overloaded_result()) +}