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.
This commit is contained in:
Slava Pestov
2025-02-18 20:12:34 -05:00
parent 725bd910be
commit 521ea46d15
2 changed files with 9 additions and 3 deletions

View File

@@ -858,9 +858,10 @@ bool ConstraintSystem::Candidate::solve(
auto constraintKind = ConstraintKind::Conversion;
if (CTP == CTP_CallArgument)
constraintKind = ConstraintKind::ArgumentConversion;
cs.addConstraint(constraintKind, cs.getType(E), CT,
cs.getConstraintLocator(E), /*isFavored=*/true);
if (!CT->hasUnboundGenericType()) {
cs.addConstraint(constraintKind, cs.getType(E), CT,
cs.getConstraintLocator(E), /*isFavored=*/true);
}
}
// Try to solve the system and record all available solutions.

View File

@@ -0,0 +1,5 @@
// RUN: %target-typecheck-verify-swift
func f(a: Array<Int>, n: Int) {
let _: Array = a.prefix(n) + a.suffix(a.count - n - 1)
}