@@ -2063,20 +2063,26 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
20632063 if (path.back().is<LocatorPathElt::PatternMatch>()) {
20642064 return true;
20652065 } else if (path.size() > 1) {
2066- // sub-pattern matching as part of the enum element matching
2067- // where sub-element is a tuple pattern e.g.
2068- // `case .foo((a: 42, _)) = question`
2069- auto lastIdx = path.size() - 1;
2070- if (path[lastIdx - 1].is<LocatorPathElt::PatternMatch>() &&
2071- path[lastIdx].is<LocatorPathElt::FunctionArgument>())
2072- return true;
2073-
2074- if (path.size() > 5) {
2075- // `case .bar(_, (_, (_, (_, (let a, _), _), _))) = question`
2076- if (path[3].is<LocatorPathElt::PatternMatch>() &&
2077- path[4].is<LocatorPathElt::FunctionArgument>() &&
2078- path[lastIdx].is<LocatorPathElt::TupleElement>())
2066+ int patternMatchIdx = 0;
2067+ for (int i = 0; i < (int)path.size(); i++) {
2068+ if (path[i].is<LocatorPathElt::PatternMatch>()) {
2069+ patternMatchIdx = i;
2070+ }
2071+ }
2072+
2073+ // sub-pattern matching as part of the enum element matching
2074+ // where sub-element is a tuple pattern e.g.
2075+ // `case .foo((a: 42, _)) = question`
2076+ if (path[patternMatchIdx].is<LocatorPathElt::PatternMatch>() &&
2077+ path[patternMatchIdx + 1].is<LocatorPathElt::FunctionArgument>())
20792078 return true;
2079+
2080+ if (path.size() > 2) {
2081+ // `case .bar(_, (_, (_, (_, (let a, _), _), _))) = question`
2082+ if (path[patternMatchIdx].is<LocatorPathElt::PatternMatch>() &&
2083+ path[patternMatchIdx + 1].is<LocatorPathElt::FunctionArgument>() &&
2084+ path[patternMatchIdx + 2].is<LocatorPathElt::TupleElement>())
2085+ return true;
20802086 }
20812087 }
20822088 }
@@ -2239,6 +2245,10 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
22392245 case ConstraintKind::Equal: {
22402246 subkind = kind;
22412247
2248+ auto &e = llvm::errs();
2249+ e << "@@ locator dump =>";
2250+ locator.dump(this);
2251+ e << "\n";
22422252 if (isInPatternMatchingContext(locator)) {
22432253 if (matcher.matchInPatternMatchingContext())
22442254 return getTypeMatchFailure(locator);
0 commit comments