Skip to content

[5.8][CSClosure] A couple of closure related fixes #62842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 4 additions & 19 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 13 additions & 1 deletion lib/Sema/CSSyntacticElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,22 @@ class TypeVariableRefFinder : public ASTWalker {
return;
}

// Don't walk into the opaque archetypes because they are not
// transparent in this context - `some P` could reference a
// type variables as substitutions which are visible only to
// the outer context.
if (type->is<OpaqueTypeArchetypeType>())
return;

if (type->hasTypeVariable()) {
SmallPtrSet<TypeVariableType *, 4> typeVars;
type->getTypeVariables(typeVars);
ReferencedVars.insert(typeVars.begin(), typeVars.end());

// Some of the type variables could be non-representative, so
// we need to recurse into `inferTypeVariables` to property
// handle them.
for (auto *typeVar : typeVars)
inferVariables(typeVar);
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %target-typecheck-verify-swift

struct Description: Hashable {
let name: String
let id: Int
}

struct Value {
let ID: Int?
}

func test(allValues: [Value]) {
// Type for `return nil` cannot be inferred at the moment because there is no join for result expressions.
let owners = Set(allValues.compactMap { // expected-error {{generic parameter 'Element' could not be inferred}}
// expected-note@-1 {{explicitly specify the generic arguments to fix this issue}}
guard let id = $0.ID else { return nil }
return Description(name: "", id: id)
})
}