@@ -1601,32 +1601,21 @@ Pattern *TypeChecker::coercePatternToType(
1601
1601
1602
1602
EEP->setSubPattern (sub);
1603
1603
} 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
1605
1605
// associated values, expand it to be semantically equivalent to an
1606
1606
// element pattern of wildcards.
1607
- Type elementType = enumTy->getTypeOfMember (elt, payloadType);
1608
1607
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 ¶m : elt->getCaseConstructorParams ()) {
1620
1609
auto *subPattern = AnyPattern::createImplicit (Context);
1621
- elements.push_back (TuplePatternElt (Identifier (), SourceLoc (),
1622
- subPattern));
1610
+ elements.emplace_back (param.getLabel (), SourceLoc (), subPattern);
1623
1611
}
1624
1612
Pattern *sub = TuplePattern::createSimple (Context, SourceLoc (),
1625
1613
elements, SourceLoc ());
1626
1614
sub->setImplicit ();
1627
1615
auto newSubOptions = subOptions;
1628
1616
newSubOptions.setContext (TypeResolverContext::EnumPatternPayload);
1629
1617
newSubOptions |= TypeResolutionFlags::FromNonInferredPattern;
1618
+ Type elementType = enumTy->getTypeOfMember (elt, payloadType);
1630
1619
sub = coercePatternToType (
1631
1620
pattern.forSubPattern (sub, /* retainTopLevel=*/ false ), elementType,
1632
1621
newSubOptions, tryRewritePattern);
0 commit comments