Skip to content

Commit 427bb32

Browse files
committed
Sema: Fix crash when diagnosing invalid assignment expression
CSGen can see an AssignExpr where the destination has an unresolved type, even in a case where no diagnostic has been emitted yet. It is then wrong to return an empty type from here, because this stops us from attempting to solve the expression, which results in no diagnostic being emitted in the end. The test case I added produces a decent diagnostic now, but the original one in the radar now just says 'ambiguous without more context'. Still, better than crashing. Fixes <rdar://problem/30685195>.
1 parent dd7b62c commit 427bb32

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

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/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)