Skip to content

Commit 3ff539b

Browse files
authored
Merge pull request swiftlang#62842 from xedin/closure-related-fixes-5.8
[5.8][CSClosure] A couple of closure related fixes
2 parents 1affdf1 + 6d681cf commit 3ff539b

File tree

4 files changed

+54
-20
lines changed

4 files changed

+54
-20
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,25 +2055,10 @@ static bool isInPatternMatchingContext(ConstraintLocatorBuilder locator) {
20552055
SmallVector<LocatorPathElt, 4> path;
20562056
(void)locator.getLocatorParts(path);
20572057

2058-
while (!path.empty() && path.back().is<LocatorPathElt::TupleType>())
2059-
path.pop_back();
2060-
2061-
if (!path.empty()) {
2062-
// Direct pattern matching between tuple pattern and tuple type.
2063-
if (path.back().is<LocatorPathElt::PatternMatch>()) {
2064-
return true;
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-
}
2075-
2076-
return false;
2058+
auto pathElement = llvm::find_if(path, [](LocatorPathElt &elt) {
2059+
return elt.is<LocatorPathElt::PatternMatch>();
2060+
});
2061+
return pathElement != path.end();
20772062
}
20782063

20792064
namespace {

lib/Sema/CSSyntacticElement.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,22 @@ class TypeVariableRefFinder : public ASTWalker {
197197
return;
198198
}
199199

200+
// Don't walk into the opaque archetypes because they are not
201+
// transparent in this context - `some P` could reference a
202+
// type variables as substitutions which are visible only to
203+
// the outer context.
204+
if (type->is<OpaqueTypeArchetypeType>())
205+
return;
206+
200207
if (type->hasTypeVariable()) {
201208
SmallPtrSet<TypeVariableType *, 4> typeVars;
202209
type->getTypeVariables(typeVars);
203-
ReferencedVars.insert(typeVars.begin(), typeVars.end());
210+
211+
// Some of the type variables could be non-representative, so
212+
// we need to recurse into `inferTypeVariables` to property
213+
// handle them.
214+
for (auto *typeVar : typeVars)
215+
inferVariables(typeVar);
204216
}
205217
}
206218
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift
2+
enum TestType {
3+
case foo
4+
case bar(Bool, (a: String, (b: String, (String, (c: String, Bool), String), String)))
5+
}
6+
7+
func test(type: TestType) -> String {
8+
let str: String = {
9+
switch type {
10+
case .foo:
11+
return ""
12+
case .bar(_, (_, (_, (_, (let c, _), _), _))):
13+
return c
14+
}
15+
}()
16+
17+
return str
18+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
struct Description: Hashable {
4+
let name: String
5+
let id: Int
6+
}
7+
8+
struct Value {
9+
let ID: Int?
10+
}
11+
12+
func test(allValues: [Value]) {
13+
// Type for `return nil` cannot be inferred at the moment because there is no join for result expressions.
14+
let owners = Set(allValues.compactMap { // expected-error {{generic parameter 'Element' could not be inferred}}
15+
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
16+
guard let id = $0.ID else { return nil }
17+
return Description(name: "", id: id)
18+
})
19+
}

0 commit comments

Comments
 (0)