Skip to content

[CSGen] A couple of improvements to pattern binding handling #38895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3918,11 +3918,22 @@ bool ConstraintSystem::generateConstraints(

/// Generate constraints for each pattern binding entry
for (unsigned index : range(patternBinding->getNumPatternEntries())) {
// Type check the pattern.
auto pattern = patternBinding->getPattern(index);
auto *pattern = TypeChecker::resolvePattern(
patternBinding->getPattern(index), dc, /*isStmtCondition=*/true);

if (!pattern)
return true;

// Type check the pattern. Note use of `forRawPattern` here instead
// of `forPatternBindingDecl` because resolved `pattern` is not
// associated with `patternBinding`.
auto contextualPattern = ContextualPattern::forRawPattern(pattern, dc);
Type patternType = TypeChecker::typeCheckPattern(contextualPattern);

// Fail early if pattern couldn't be type-checked.
if (!patternType || patternType->hasError())
return true;

auto init = patternBinding->getInit(index);
if (!init) {
llvm_unreachable("Unsupported pattern binding entry");
Expand Down