Skip to content

Commit 1909e83

Browse files
committed
fix <rdar://problem/23798944> = vs. == in Swift if string character count statement causes segmentation fault
This is a really nasty problem where we'd explode trying to unify type variables we found in the constraint graph, that didn't exist in the constraint system. This happened because diagnostic generation is simplifying the system in "ContinueAfterFailures" mode to try to get to a minimal system (to avoid producing an error message about trivially solvable constraints that only exist due to the solver stopping early) and in this mode we would see an erroneous constraint, remove it from the constraint system, but not the constraint graph. This only mattered in ContinueAfterFailures. As with many things, the fix is pretty simple once the onion is peeled enough to find the stinky part lurking inside.
1 parent 17fe37d commit 1909e83

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ bool ConstraintSystem::simplify(bool ContinueAfterFailures) {
336336

337337
if (solverState)
338338
solverState->retiredConstraints.push_front(constraint);
339+
else
340+
CG.removeConstraint(constraint);
339341

340342
break;
341343

test/Constraints/assignment.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,11 @@ func value2(inout x: Int) {}
4949
value2(&_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
5050
value(_) // expected-error{{'_' can only appear in a pattern or on the left side of an assignment}}
5151

52+
53+
// <rdar://problem/23798944> = vs. == in Swift if string character count statement causes segmentation fault
54+
func f23798944() {
55+
let s = ""
56+
if s.characters.count = 0 { // expected-error {{cannot assign to property: 'count' is a get-only property}}
57+
}
58+
}
59+

0 commit comments

Comments
 (0)