Skip to content

Commit a974aaa

Browse files
committed
Added test that Optional.none is correctly cast in a generic context.
1 parent 3d05edd commit a974aaa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

test/stdlib/Casts.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ CastsTests.test("No overrelease of existential boxes in failed casts") {
4343
}
4444
}
4545
}
46-
46+
4747
let err: Error = ErrClass()
4848
bar(err)
4949
}
@@ -70,6 +70,16 @@ CastsTests.test("Multi-level optionals can be casted") {
7070
testFailure(42, from: Int???.self, to: String.self)
7171
}
7272

73+
// Test for SR-9837: Optional<T>.none not casting to Optional<U>.none in generic context
74+
CastsTests.test("Optional<T>.none can be casted to Optional<U>.none in generic context") {
75+
func test<T>(_ type: T.Type) -> T? {
76+
return Any?.none as? T
77+
}
78+
79+
expectEqual(type(of: test(Bool.self)), Bool?.self)
80+
expectEqual(type(of: test(Bool?.self)), Bool??.self)
81+
}
82+
7383
#if _runtime(_ObjC)
7484
extension CFBitVector : P {
7585
static func makeImmutable(from values: Array<UInt8>) -> CFBitVector {

0 commit comments

Comments
 (0)