Skip to content

Commit f37c9a7

Browse files
authored
Merge pull request swiftlang#30165 from xedin/rdar-59703585
[Diagnostics] Don't fix partial mismatch for sub-types associated with…
2 parents aaab186 + f7b2645 commit f37c9a7

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,6 +1884,12 @@ bool ContextualFailure::diagnoseAsError() {
18841884
return true;
18851885
}
18861886

1887+
if (isa<AssignExpr>(anchor)) {
1888+
emitDiagnostic(anchor->getLoc(), diag::cannot_convert_assign,
1889+
getFromType(), getToType());
1890+
return true;
1891+
}
1892+
18871893
return false;
18881894
}
18891895

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3788,6 +3788,12 @@ bool ConstraintSystem::repairFailures(
37883788
tupleLocator->isLastElement<LocatorPathElt::GenericArgument>())
37893789
break;
37903790

3791+
// If the mismatch is a part of either optional-to-optional or
3792+
// value-to-optional conversions, let's allow fix refer to a complete
3793+
// top level type and not just a part of it.
3794+
if (tupleLocator->findLast<LocatorPathElt::OptionalPayload>())
3795+
break;
3796+
37913797
ConstraintFix *fix;
37923798
if (tupleLocator->isLastElement<LocatorPathElt::FunctionArgument>()) {
37933799
fix = AllowFunctionTypeMismatch::create(*this, lhs, rhs, tupleLocator, index);

test/Constraints/function_conversion.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,15 @@ noEscapeParam = takesAny // expected-error {{converting non-escaping value to 'A
6868
func rdar_59773317(x: () -> Int) -> (() -> Int)? { // expected-note {{parameter 'x' is implicitly non-escaping}}
6969
return x // expected-error {{using non-escaping parameter 'x' in a context expecting an @escaping closure}}
7070
}
71+
72+
// rdar://problem/59703585 - Wrong error message when signature of a C function type and Swift implementation mismatch
73+
func rdar_59703585() {
74+
typealias Fn = @convention(c) (UnsafePointer<Int8>?, UnsafeMutableRawPointer?) -> Void
75+
76+
func swiftCallback(someString: UnsafePointer<Int8>, someObject: UnsafeMutableRawPointer?) {}
77+
78+
var cb: Fn? = nil
79+
80+
cb = swiftCallback
81+
// expected-error@-1 {{cannot assign value of type '(UnsafePointer<Int8>, UnsafeMutableRawPointer?) -> ()' to type 'Fn?' (aka 'Optional<@convention(c) (Optional<UnsafePointer<Int8>>, Optional<UnsafeMutableRawPointer>) -> ()>')}}
82+
}

0 commit comments

Comments
 (0)