use dynamic variables and uppdate some logic

This commit is contained in:
takeshi-1000
2022-12-27 19:53:36 +09:00
parent 4bf8496874
commit 279dc4fe6b

View File

@@ -2063,20 +2063,26 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
if (path.back().is<LocatorPathElt::PatternMatch>()) { if (path.back().is<LocatorPathElt::PatternMatch>()) {
return true; return true;
} else if (path.size() > 1) { } else if (path.size() > 1) {
// sub-pattern matching as part of the enum element matching int patternMatchIdx = 0;
// where sub-element is a tuple pattern e.g. for (int i = 0; i < (int)path.size(); i++) {
// `case .foo((a: 42, _)) = question` if (path[i].is<LocatorPathElt::PatternMatch>()) {
auto lastIdx = path.size() - 1; patternMatchIdx = i;
if (path[lastIdx - 1].is<LocatorPathElt::PatternMatch>() && }
path[lastIdx].is<LocatorPathElt::FunctionArgument>()) }
return true;
// sub-pattern matching as part of the enum element matching
if (path.size() > 5) { // where sub-element is a tuple pattern e.g.
// `case .bar(_, (_, (_, (_, (let a, _), _), _))) = question` // `case .foo((a: 42, _)) = question`
if (path[3].is<LocatorPathElt::PatternMatch>() && if (path[patternMatchIdx].is<LocatorPathElt::PatternMatch>() &&
path[4].is<LocatorPathElt::FunctionArgument>() && path[patternMatchIdx + 1].is<LocatorPathElt::FunctionArgument>())
path[lastIdx].is<LocatorPathElt::TupleElement>())
return true; return true;
if (path.size() > 2) {
// `case .bar(_, (_, (_, (_, (let a, _), _), _))) = question`
if (path[patternMatchIdx].is<LocatorPathElt::PatternMatch>() &&
path[patternMatchIdx + 1].is<LocatorPathElt::FunctionArgument>() &&
path[patternMatchIdx + 2].is<LocatorPathElt::TupleElement>())
return true;
} }
} }
} }
@@ -2239,6 +2245,10 @@ ConstraintSystem::matchTupleTypes(TupleType *tuple1, TupleType *tuple2,
case ConstraintKind::Equal: { case ConstraintKind::Equal: {
subkind = kind; subkind = kind;
auto &e = llvm::errs();
e << "@@ locator dump =>";
locator.dump(this);
e << "\n";
if (isInPatternMatchingContext(locator)) { if (isInPatternMatchingContext(locator)) {
if (matcher.matchInPatternMatchingContext()) if (matcher.matchInPatternMatchingContext())
return getTypeMatchFailure(locator); return getTypeMatchFailure(locator);