mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSSimplify] Fix sub-pattern matching logic related closure and enum element (#62777)
* [CSSimplify] fix pattern matching logic which is as part of the enum element for closure
* add test
* Fixed logic to apply to N levels of nesting
* update tests that take into account N levels of nesting.
* fix indentation
* use dynamic variables and uppdate some logic
* Revert "use dynamic variables and uppdate some logic"
This reverts commit 279dc4fe6b.
* fix logic to only see pattern matches
* clean up unnecessary logic
Co-authored-by: Luciano Almeida <passos.luciano@outlook.com>
* Clean up unnecessary logic(2)
* remove dropping
* Fix documentation comments to match current context
* clean up unnecessary logic
* remove comments
Co-authored-by: Luciano Almeida <passos.luciano@outlook.com>
This commit is contained in:
@@ -2055,25 +2055,10 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
|
||||
SmallVector<LocatorPathElt, 4> path;
|
||||
(void)locator.getLocatorParts(path);
|
||||
|
||||
while (!path.empty() && path.back().is<LocatorPathElt::TupleType>())
|
||||
path.pop_back();
|
||||
|
||||
if (!path.empty()) {
|
||||
// Direct pattern matching between tuple pattern and tuple type.
|
||||
if (path.back().is<LocatorPathElt::PatternMatch>()) {
|
||||
return true;
|
||||
} else if (path.size() > 1) {
|
||||
// sub-pattern matching as part of the enum element matching
|
||||
// where sub-element is a tuple pattern e.g.
|
||||
// `case .foo((a: 42, _)) = question`
|
||||
auto lastIdx = path.size() - 1;
|
||||
if (path[lastIdx - 1].is<LocatorPathElt::PatternMatch>() &&
|
||||
path[lastIdx].is<LocatorPathElt::FunctionArgument>())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
auto pathElement = llvm::find_if(path, [](LocatorPathElt &elt) {
|
||||
return elt.is<LocatorPathElt::PatternMatch>();
|
||||
});
|
||||
return pathElement != path.end();
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
enum TestType {
|
||||
case foo
|
||||
case bar(Bool, (a: String, (b: String, (String, (c: String, Bool), String), String)))
|
||||
}
|
||||
|
||||
func test(type: TestType) -> String {
|
||||
let str: String = {
|
||||
switch type {
|
||||
case .foo:
|
||||
return ""
|
||||
case .bar(_, (_, (_, (_, (let c, _), _), _))):
|
||||
return c
|
||||
}
|
||||
}()
|
||||
|
||||
return str
|
||||
}
|
||||
Reference in New Issue
Block a user