Skip to content

[CS] Connect isolated conjunctions to referenced VarDecls #63456

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 1 commit into from
Feb 6, 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
12 changes: 6 additions & 6 deletions lib/Sema/CSSyntacticElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,24 @@ class TypeVariableRefFinder : public ASTWalker {
}
};

/// Find any references to not yet resolved outer closure parameters
/// used in the body of the inner closure. This is required because
/// Find any references to not yet resolved outer VarDecls (including closure
/// parameters) used in the body of the inner closure. This is required because
/// isolated conjunctions, just like single-expression closures, have
/// to be connected to type variables they are going to use, otherwise
/// they'll get placed in a separate solver component and would never
/// produce a solution.
class UnresolvedClosureParameterCollector : public ASTWalker {
class UnresolvedVarCollector : public ASTWalker {
ConstraintSystem &CS;

llvm::SmallSetVector<TypeVariableType *, 4> Vars;

public:
UnresolvedClosureParameterCollector(ConstraintSystem &cs) : CS(cs) {}
UnresolvedVarCollector(ConstraintSystem &cs) : CS(cs) {}

PreWalkResult<Expr *> walkToExprPre(Expr *expr) override {
if (auto *DRE = dyn_cast<DeclRefExpr>(expr)) {
auto *decl = DRE->getDecl();
if (isa<ParamDecl>(decl)) {
if (isa<VarDecl>(decl)) {
if (auto type = CS.getTypeIfAvailable(decl)) {
if (auto *typeVar = type->getAs<TypeVariableType>()) {
Vars.insert(typeVar);
Expand Down Expand Up @@ -342,7 +342,7 @@ static void createConjunction(ConstraintSystem &cs,
isIsolated = true;
}

UnresolvedClosureParameterCollector paramCollector(cs);
UnresolvedVarCollector paramCollector(cs);

for (const auto &entry : elements) {
ASTNode element = std::get<0>(entry);
Expand Down
6 changes: 6 additions & 0 deletions test/Constraints/rdar105080067.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// RUN: %target-typecheck-verify-swift

// rdar://105080067 - This isn't currently allowed but make sure we don't
// emit a spurious "cannot reference invalid declaration" error.
for b in [true] where if b { true } else { false } {}
// expected-error@-1 {{'if' may only be used as expression in return, throw, or as the source of an assignment}}