Skip to content

Commit 9e48723

Browse files
committed
[Sema] Avoid relying on ParenType in coercePatternToType
I missed this in my other Sema ParenType PR, avoid relying on ParenType here.
1 parent e71fb9e commit 9e48723

File tree

1 file changed

+4
-15
lines changed

1 file changed

+4
-15
lines changed

lib/Sema/TypeCheckPattern.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,32 +1601,21 @@ Pattern *TypeChecker::coercePatternToType(
16011601

16021602
EEP->setSubPattern(sub);
16031603
} else if (payloadType) {
1604-
// Else if the element pattern has no sub-pattern but the element type has
1604+
// Else if the element pattern has no sub-pattern but the enum case has
16051605
// associated values, expand it to be semantically equivalent to an
16061606
// element pattern of wildcards.
1607-
Type elementType = enumTy->getTypeOfMember(elt, payloadType);
16081607
SmallVector<TuplePatternElt, 8> elements;
1609-
if (auto *TTy = dyn_cast<TupleType>(elementType.getPointer())) {
1610-
for (auto &elt : TTy->getElements()) {
1611-
auto *subPattern = AnyPattern::createImplicit(Context);
1612-
elements.push_back(TuplePatternElt(elt.getName(), SourceLoc(),
1613-
subPattern));
1614-
}
1615-
} else {
1616-
auto parenTy = dyn_cast<ParenType>(elementType.getPointer());
1617-
assert(parenTy && "Associated value type is neither paren nor tuple?");
1618-
(void)parenTy;
1619-
1608+
for (auto &param : elt->getCaseConstructorParams()) {
16201609
auto *subPattern = AnyPattern::createImplicit(Context);
1621-
elements.push_back(TuplePatternElt(Identifier(), SourceLoc(),
1622-
subPattern));
1610+
elements.emplace_back(param.getLabel(), SourceLoc(), subPattern);
16231611
}
16241612
Pattern *sub = TuplePattern::createSimple(Context, SourceLoc(),
16251613
elements, SourceLoc());
16261614
sub->setImplicit();
16271615
auto newSubOptions = subOptions;
16281616
newSubOptions.setContext(TypeResolverContext::EnumPatternPayload);
16291617
newSubOptions |= TypeResolutionFlags::FromNonInferredPattern;
1618+
Type elementType = enumTy->getTypeOfMember(elt, payloadType);
16301619
sub = coercePatternToType(
16311620
pattern.forSubPattern(sub, /*retainTopLevel=*/false), elementType,
16321621
newSubOptions, tryRewritePattern);

0 commit comments

Comments
 (0)