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