Skip to content

Commit 2137e1b

Browse files
committed
[TypeChecker] NFC: Add a test-case to test condition requirements interaction with transitive conformance checks
1 parent 6add8f2 commit 2137e1b

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/Constraints/protocols.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,3 +454,23 @@ func test_inference_through_implicit_conversion() {
454454
let _: UnsafePointer<C> = test([C()]) // Ok - argument is implicitly converted to a pointer
455455
let _: AnyHashable = test(C()) // Ok - argument is implicitly converted to `AnyHashable` because it's Hashable
456456
}
457+
458+
// Make sure that conformances transitively checked through implicit conversions work with conditional requirements
459+
protocol TestCond {}
460+
461+
extension Optional : TestCond where Wrapped == Int? {}
462+
463+
func simple<T : TestCond>(_ x: T) -> T { x }
464+
465+
func overloaded<T: TestCond>(_ x: T) -> T { x }
466+
func overloaded<T: TestCond>(_ x: String) -> T { fatalError() }
467+
468+
func overloaded_result() -> Int { 42 }
469+
func overloaded_result() -> String { "" }
470+
471+
func test_arg_conformance_with_conditional_reqs(i: Int) {
472+
let _: Int?? = simple(i)
473+
let _: Int?? = overloaded(i)
474+
let _: Int?? = simple(overloaded_result())
475+
let _: Int?? = overloaded(overloaded_result())
476+
}

0 commit comments

Comments
 (0)