Skip to content

Commit 7d90297

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 c1b3d2d commit 7d90297

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
@@ -1608,32 +1608,21 @@ Pattern *TypeChecker::coercePatternToType(
16081608

16091609
EEP->setSubPattern(sub);
16101610
} else if (payloadType) {
1611-
// Else if the element pattern has no sub-pattern but the element type has
1611+
// Else if the element pattern has no sub-pattern but the enum case has
16121612
// associated values, expand it to be semantically equivalent to an
16131613
// element pattern of wildcards.
1614-
Type elementType = enumTy->getTypeOfMember(elt, payloadType);
16151614
SmallVector<TuplePatternElt, 8> elements;
1616-
if (auto *TTy = dyn_cast<TupleType>(elementType.getPointer())) {
1617-
for (auto &elt : TTy->getElements()) {
1618-
auto *subPattern = AnyPattern::createImplicit(Context);
1619-
elements.push_back(TuplePatternElt(elt.getName(), SourceLoc(),
1620-
subPattern));
1621-
}
1622-
} else {
1623-
auto parenTy = dyn_cast<ParenType>(elementType.getPointer());
1624-
assert(parenTy && "Associated value type is neither paren nor tuple?");
1625-
(void)parenTy;
1626-
1615+
for (auto &param : elt->getCaseConstructorParams()) {
16271616
auto *subPattern = AnyPattern::createImplicit(Context);
1628-
elements.push_back(TuplePatternElt(Identifier(), SourceLoc(),
1629-
subPattern));
1617+
elements.emplace_back(param.getLabel(), SourceLoc(), subPattern);
16301618
}
16311619
Pattern *sub = TuplePattern::createSimple(Context, SourceLoc(),
16321620
elements, SourceLoc());
16331621
sub->setImplicit();
16341622
auto newSubOptions = subOptions;
16351623
newSubOptions.setContext(TypeResolverContext::EnumPatternPayload);
16361624
newSubOptions |= TypeResolutionFlags::FromNonInferredPattern;
1625+
Type elementType = enumTy->getTypeOfMember(elt, payloadType);
16371626
sub = coercePatternToType(
16381627
pattern.forSubPattern(sub, /*retainTopLevel=*/false), elementType,
16391628
newSubOptions, tryRewritePattern);

0 commit comments

Comments
 (0)