Skip to content

Commit 63c1f8d

Browse files
committed
[TypeChecker] Resolve a crash about ambiguous assignment closure
Having an invalid assignment in a closure could make the type checker fail without providing a diagnostic, eventually crashing the compiler. Now a diagnostic is provided. This resolves SR-3053/SR-3073
1 parent ff2a72d commit 63c1f8d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3294,8 +3294,11 @@ namespace {
32943294
//
32953295
// FIXME: This is also computed when the constraint system is set up.
32963296
auto destTy = cs.computeAssignDestType(expr->getDest(), expr->getLoc());
3297-
if (!destTy)
3297+
if (!destTy) {
3298+
cs.TC.diagnose(expr->getLoc(), diag::type_of_expression_is_ambiguous)
3299+
.highlight(expr->getSourceRange());
32983300
return nullptr;
3301+
}
32993302
expr->getDest()->propagateLValueAccessKind(AccessKind::Write);
33003303

33013304
// Convert the source to the simplified destination type.

test/expr/closure/inference.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,23 @@ func sr1976<T>(_ closure: (inout T) -> Void) {
4545
}
4646

4747
sr1976({ $0 += 2 })
48+
49+
// SR-3073: UnresolvedDotExpr in single expression closure
50+
51+
func sr3073<S, T>(_ closure:(inout S, T) -> ()) {}
52+
53+
sr3073({ $0.number1 = $1 }) //expected-error {{type of expression is ambiguous without more context}}
54+
55+
struct SR3073Lense<Whole, Part> {
56+
let set: (inout Whole, Part) -> ()
57+
}
58+
59+
struct SR3073 {
60+
var number1: Int
61+
62+
func lenses() {
63+
let _: SR3073Lense<SR3073, Int> = SR3073Lense(
64+
set: { $0.number1 = $1 }
65+
)
66+
}
67+
}

0 commit comments

Comments
 (0)