Skip to content

Commit 4e43e31

Browse files
committed
Sema: Don't record constraints containing UnboundGenericType from shrink()
Something changed here between the removal of shrink() and it's re-introduction, and we now record constraints that contain UnboundGenericType, which crashes in matchTypes(). As a narrow workaround, let's just ignore the contextual type if contains an UnboundGenericType. Fixes rdar://145092838.
1 parent 63b7f05 commit 4e43e31

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,10 @@ bool ConstraintSystem::Candidate::solve(
858858
auto constraintKind = ConstraintKind::Conversion;
859859
if (CTP == CTP_CallArgument)
860860
constraintKind = ConstraintKind::ArgumentConversion;
861-
862-
cs.addConstraint(constraintKind, cs.getType(E), CT,
863-
cs.getConstraintLocator(E), /*isFavored=*/true);
861+
if (!CT->hasUnboundGenericType()) {
862+
cs.addConstraint(constraintKind, cs.getType(E), CT,
863+
cs.getConstraintLocator(E), /*isFavored=*/true);
864+
}
864865
}
865866

866867
// Try to solve the system and record all available solutions.

test/Constraints/rdar145092838.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
func f(a: Array<Int>, n: Int) {
4+
let _: Array = a.prefix(n) + a.suffix(a.count - n - 1)
5+
}

0 commit comments

Comments
 (0)