mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
use dynamic variables and uppdate some logic
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user