Skip to content

Commit 487d59e

Browse files
authored
Merge pull request #38895 from xedin/fix-contextual-pattern-in-pattern-binding
[CSGen] A couple of improvements to pattern binding handling
2 parents 8b8fdfa + 56e9fa6 commit 487d59e

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3918,11 +3918,22 @@ bool ConstraintSystem::generateConstraints(
39183918

39193919
/// Generate constraints for each pattern binding entry
39203920
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
3921-
// Type check the pattern.
3922-
auto pattern = patternBinding->getPattern(index);
3921+
auto *pattern = TypeChecker::resolvePattern(
3922+
patternBinding->getPattern(index), dc, /*isStmtCondition=*/true);
3923+
3924+
if (!pattern)
3925+
return true;
3926+
3927+
// Type check the pattern. Note use of `forRawPattern` here instead
3928+
// of `forPatternBindingDecl` because resolved `pattern` is not
3929+
// associated with `patternBinding`.
39233930
auto contextualPattern = ContextualPattern::forRawPattern(pattern, dc);
39243931
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);
39253932

3933+
// Fail early if pattern couldn't be type-checked.
3934+
if (!patternType || patternType->hasError())
3935+
return true;
3936+
39263937
auto init = patternBinding->getInit(index);
39273938
if (!init) {
39283939
llvm_unreachable("Unsupported pattern binding entry");

0 commit comments

Comments
 (0)