@@ -2063,20 +2063,26 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
2063
2063
if (path.back().is<LocatorPathElt::PatternMatch>()) {
2064
2064
return true;
2065
2065
} 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>())
2079
2078
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;
2080
2086
}
2081
2087
}
2082
2088
}
@@ -2239,6 +2245,10 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
2239
2245
case ConstraintKind::Equal: {
2240
2246
subkind = kind;
2241
2247
2248
+ auto &e = llvm::errs();
2249
+ e << "@@ locator dump =>";
2250
+ locator.dump(this);
2251
+ e << "\n";
2242
2252
if (isInPatternMatchingContext(locator)) {
2243
2253
if (matcher.matchInPatternMatchingContext())
2244
2254
return getTypeMatchFailure(locator);
0 commit comments