Skip to content

Commit 6aa7e3b

Browse files
authored
Merge pull request #9366 from slavapestov/fix-two-diagnostics-crashers
Fix two diagnostics crashers
2 parents 1e93d73 + 427bb32 commit 6aa7e3b

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,13 +325,17 @@ static DeclName getOverloadChoiceName(ArrayRef<OverloadChoice> choices) {
325325

326326
/// Returns true if any diagnostics were emitted.
327327
static bool
328-
tryDiagnoseTrailingClosureAmbiguity(TypeChecker &tc, const Expr *expr,
328+
tryDiagnoseTrailingClosureAmbiguity(TypeChecker &tc,
329+
const Expr *expr,
330+
const Expr *anchor,
329331
ArrayRef<OverloadChoice> choices) {
330332
auto *callExpr = dyn_cast<CallExpr>(expr);
331333
if (!callExpr)
332334
return false;
333335
if (!callExpr->hasTrailingClosure())
334336
return false;
337+
if (callExpr->getFn() != anchor)
338+
return false;
335339

336340
llvm::SmallMapVector<Identifier, const ValueDecl *, 8> choicesByLabel;
337341
for (const OverloadChoice &choice : choices) {
@@ -465,7 +469,7 @@ static bool diagnoseAmbiguity(ConstraintSystem &cs,
465469
: diag::ambiguous_decl_ref,
466470
name);
467471

468-
if (tryDiagnoseTrailingClosureAmbiguity(tc, expr, overload.choices))
472+
if (tryDiagnoseTrailingClosureAmbiguity(tc, expr, anchor, overload.choices))
469473
return true;
470474

471475
// Emit candidates. Use a SmallPtrSet to make sure only emit a particular

lib/Sema/CSGen.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2672,8 +2672,12 @@ namespace {
26722672
// Compute the type to which the source must be converted to allow
26732673
// assignment to the destination.
26742674
auto destTy = CS.computeAssignDestType(expr->getDest(), expr->getLoc());
2675-
if (!destTy || destTy->getRValueType()->is<UnresolvedType>())
2675+
if (!destTy)
26762676
return Type();
2677+
if (destTy->getRValueType()->is<UnresolvedType>()) {
2678+
return CS.createTypeVariable(CS.getConstraintLocator(expr),
2679+
TVO_CanBindToLValue);
2680+
}
26772681

26782682
// The source must be convertible to the destination.
26792683
CS.addConstraint(ConstraintKind::Conversion,

test/Constraints/diagnostics.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -931,3 +931,12 @@ let _ = (r29850459() ? r29850459_a : r29850459_b) + 42.0 // expected-error {{bin
931931
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
932932
let _ = ((r29850459_flag || r29850459()) ? r29850459_a : r29850459_b) + 42.0 // expected-error {{binary operator '+' cannot be applied to operands of type 'Int' and 'Double'}}
933933
// expected-note@-1 {{overloads for '+' exist with these partially matching parameter lists: (Double, Double), (Int, Int), (Int, UnsafeMutablePointer<Pointee>), (Int, UnsafePointer<Pointee>)}}
934+
935+
// Ambiguous overload inside a trailing closure
936+
937+
func ambiguousCall() -> Int {} // expected-note {{found this candidate}}
938+
func ambiguousCall() -> Float {} // expected-note {{found this candidate}}
939+
940+
func takesClosure(fn: () -> ()) {}
941+
942+
takesClosure() { ambiguousCall() } // expected-error {{ambiguous use of 'ambiguousCall()'}}

test/Constraints/lvalues.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,13 @@ func r23331567(_ fn: (_ x: inout Int) -> Void) {
232232
}
233233
r23331567 { $0 += 1 }
234234

235+
// <rdar://problem/30685195> Compiler crash with invalid assignment
236+
struct G<T> {
237+
subscript(x: Int) -> T { get { } nonmutating set { } }
238+
// expected-note@-1 {{'subscript' declared here}}
239+
}
240+
241+
func wump<T>(to: T, _ body: (G<T>) -> ()) {}
242+
243+
wump(to: 0, { $0[] = 0 })
244+
// expected-error@-1 {{missing argument for parameter #1 in call}}

0 commit comments

Comments
 (0)