Skip to content

[DNM] Fix SILGenPattern fallthrough issues. #22988

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

Closed
Closed
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
18 changes: 17 additions & 1 deletion include/swift/AST/Stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#ifndef SWIFT_AST_STMT_H
#define SWIFT_AST_STMT_H

#include "swift/AST/ASTNode.h"
#include "swift/AST/Availability.h"
#include "swift/AST/AvailabilitySpec.h"
#include "swift/AST/ASTNode.h"
#include "swift/AST/IfConfigClause.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/Basic/NullablePtr.h"
#include "llvm/ADT/TinyPtrVector.h"
#include "llvm/Support/TrailingObjects.h"

namespace swift {
Expand Down Expand Up @@ -943,6 +944,8 @@ class CaseStmt final : public Stmt,

llvm::PointerIntPair<Stmt *, 1, bool> BodyAndHasBoundDecls;

Optional<MutableArrayRef<VarDecl>> CaseBodyVariables;

CaseStmt(SourceLoc CaseLoc, ArrayRef<CaseLabelItem> CaseLabelItems,
bool HasBoundDecls, SourceLoc UnknownAttrLoc, SourceLoc ColonLoc,
Stmt *Body, Optional<bool> Implicit);
Expand Down Expand Up @@ -990,6 +993,19 @@ class CaseStmt final : public Stmt,
return UnknownAttrLoc.isValid();
}

bool isCaseBodyVariablesInitialized() const {
return CaseBodyVariables.hasValue();
}

ArrayRef<VarDecl> getCaseBodyVariables() const { return *CaseBodyVariables; }

MutableArrayRef<VarDecl> getCaseBodyVariables() { return *CaseBodyVariables; }

void setCaseBodyVariables(MutableArrayRef<VarDecl> Variables) {
assert(!CaseBodyVariables && "Setting a case stmts case body vars twice?!");
CaseBodyVariables = Variables;
}

static bool classof(const Stmt *S) { return S->getKind() == StmtKind::Case; }
};

Expand Down
18 changes: 18 additions & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,24 @@ class PrintStmt : public StmtVisitor<PrintStmt> {
printCommon(S, "case_stmt");
if (S->hasUnknownAttr())
OS << " @unknown";

if (S->getCaseBodyVariables().size()) {
OS << '\n';
OS.indent(Indent + 2);
PrintWithColorRAII(OS, ParenthesisColor) << '(';
PrintWithColorRAII(OS, StmtColor) << "case_body_variables";
OS << '\n';
for (auto &vd : S->getCaseBodyVariables()) {
OS.indent(2);
// TODO: Printing a var decl does an Indent ... dump(vd) ... '\n'. We
// should see if we can factor this dumping so that the caller of
// printRec(VarDecl) has more control over the printing.
printRec(&vd);
}
OS.indent(Indent + 2);
PrintWithColorRAII(OS, ParenthesisColor) << ')';
}

for (const auto &LabelItem : S->getCaseLabelItems()) {
OS << '\n';
OS.indent(Indent + 2);
Expand Down
10 changes: 8 additions & 2 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2931,8 +2931,14 @@ void FindLocalVal::visitCaseStmt(CaseStmt *S) {
}
}
}
if (!inPatterns && !items.empty())
checkPattern(items[0].getPattern(), DeclVisibilityKind::LocalVariable);

// Then check the var decls for the case body.
if (!inPatterns && !items.empty()) {
for (auto &vd : S->getCaseBodyVariables()) {
checkValueDecl(&vd, DeclVisibilityKind::LocalVariable);
}
}

visit(S->getBody());
}

Expand Down
Loading