Skip to content

Commit 972de2e

Browse files
authored
Merge pull request #30627 from LucianoPAlmeida/SR-12382-improve-pointer-conversion-mismatch-diag
[SR-12382] Improve optional pointer conversion mismatch diagnostics
2 parents 22d7267 + 822b424 commit 972de2e

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,15 @@ bool GenericArgumentsMismatchFailure::diagnoseAsError() {
674674
}
675675
break;
676676
}
677+
678+
case ConstraintLocator::OptionalPayload: {
679+
// If we have an inout expression, this comes from an
680+
// InoutToPointer argument mismatch failure.
681+
if (isa<InOutExpr>(anchor)) {
682+
diagnostic = diag::cannot_convert_argument_value;
683+
}
684+
break;
685+
}
677686

678687
case ConstraintLocator::TupleElement: {
679688
auto *anchor = getRawAnchor();

test/Constraints/valid_pointer_conversions.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func givesPtr(_ str: String) {
3131
takesDoubleOptionalPtr(i) // expected-error {{cannot convert value of type 'Int' to expected argument type 'UnsafeRawPointer??'}}
3232
takesMutableDoubleOptionalPtr(arr) // expected-error {{cannot convert value of type '[Int]' to expected argument type 'UnsafeMutableRawPointer??'}}
3333

34-
// FIXME(SR-12382): Poor diagnostic.
35-
takesMutableDoubleOptionalTypedPtr(&i) // expected-error {{type of expression is ambiguous without more context}}
34+
takesMutableDoubleOptionalTypedPtr(&i) // expected-error {{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Double>'}}
35+
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'Double') are expected to be equal}}
3636
}
37+
38+
// SR12382
39+
func SR12382(_ x: UnsafeMutablePointer<Double>??) {}
40+
41+
var i = 0
42+
SR12382(&i) // expected-error {{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Double>'}}
43+
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('Int' and 'Double') are expected to be equal}}

0 commit comments

Comments
 (0)