Skip to content

Commit 45dc909

Browse files
committed
[test] Add regression test for SR-9090
We didn't use to accept pointer conversions passed to double optional parameters, but do now.
1 parent cd7bc73 commit 45dc909

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

test/Constraints/valid_pointer_conversions.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,30 @@ func foo(_ a: [[UInt8]], _ p: [UnsafeRawPointer]) {
77
// rdar://problem/44658089
88
func takesPtr(_: UnsafePointer<UInt8>) {}
99

10+
func takesDoubleOptionalPtr(_ x: UnsafeRawPointer??) {}
11+
func takesMutableDoubleOptionalPtr(_ x: UnsafeMutableRawPointer??) {}
12+
func takesMutableDoubleOptionalTypedPtr(_ x: UnsafeMutablePointer<Double>??) {}
13+
1014
func givesPtr(_ str: String) {
1115
takesPtr(UnsafePointer(str)) // expected-warning {{initialization of 'UnsafePointer<UInt8>' results in a dangling pointer}}
1216
// expected-note @-1 {{implicit argument conversion from 'String' to 'UnsafePointer<UInt8>' produces a pointer valid only for the duration of the call to 'init(_:)'}}
1317
// expected-note@-2 {{use the 'withCString' method on String in order to explicitly convert argument to pointer valid for a defined scope}}
18+
19+
var i = 0
20+
var d = 0.0
21+
var arr = [1, 2, 3]
22+
23+
// SR-9090: Allow double optional promotion for pointer conversions.
24+
takesDoubleOptionalPtr(&arr)
25+
takesDoubleOptionalPtr(arr)
26+
takesDoubleOptionalPtr(str)
27+
takesMutableDoubleOptionalPtr(&i)
28+
takesMutableDoubleOptionalPtr(&arr)
29+
takesMutableDoubleOptionalTypedPtr(&d)
30+
31+
takesDoubleOptionalPtr(i) // expected-error {{cannot convert value of type 'Int' to expected argument type 'UnsafeRawPointer??'}}
32+
takesMutableDoubleOptionalPtr(arr) // expected-error {{cannot convert value of type '[Int]' to expected argument type 'UnsafeMutableRawPointer??'}}
33+
34+
// FIXME(SR-12382): Poor diagnostic.
35+
takesMutableDoubleOptionalTypedPtr(&i) // expected-error {{type of expression is ambiguous without more context}}
1436
}

0 commit comments

Comments
 (0)