Skip to content

Commit 6cbdca4

Browse files
committed
[Sema] Remove LeaveFunctionBodyUnchecked flag from DeclChecker
At least for now, ide::typeCheckContextAt() doesn't call 'typeCheckASTNodeAtLoc()' with function decl signature position. Also, 'getIntefaceType()' on function reference doesn't call decl checker. So we don't need to propagate it.
1 parent 7e402e1 commit 6cbdca4

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,7 +1279,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
12791279
public:
12801280
ASTContext &Ctx;
12811281
SourceFile *SF;
1282-
bool LeaveFunctionBodyUnchecked;
12831282

12841283
explicit DeclChecker(ASTContext &ctx, SourceFile *SF) : Ctx(ctx), SF(SF) {}
12851284

@@ -2244,9 +2243,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
22442243
}
22452244
}
22462245

2247-
if (LeaveFunctionBodyUnchecked) {
2248-
// DO nothing.
2249-
} else if (requiresDefinition(FD) && !FD->hasBody()) {
2246+
if (requiresDefinition(FD) && !FD->hasBody()) {
22502247
// Complain if we should have a body.
22512248
FD->diagnose(diag::func_decl_without_brace);
22522249
} else if (FD->getDeclContext()->isLocalContext()) {
@@ -2579,9 +2576,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25792576

25802577
checkAccessControl(CD);
25812578

2582-
if (LeaveFunctionBodyUnchecked) {
2583-
// Do nothing.
2584-
} else if (requiresDefinition(CD) && !CD->hasBody()) {
2579+
if (requiresDefinition(CD) && !CD->hasBody()) {
25852580
// Complain if we should have a body.
25862581
CD->diagnose(diag::missing_initializer_def);
25872582
} else if (CD->getDeclContext()->isLocalContext()) {
@@ -2599,9 +2594,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25992594
void visitDestructorDecl(DestructorDecl *DD) {
26002595
TypeChecker::checkDeclAttributes(DD);
26012596

2602-
if (LeaveFunctionBodyUnchecked) {
2603-
// Do nothing.
2604-
} else if (DD->getDeclContext()->isLocalContext()) {
2597+
if (DD->getDeclContext()->isLocalContext()) {
26052598
// Check local function bodies right away.
26062599
TypeChecker::typeCheckAbstractFunctionBody(DD);
26072600
} else if (shouldSkipBodyTypechecking(DD)) {
@@ -2613,9 +2606,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26132606
};
26142607
} // end anonymous namespace
26152608

2616-
void TypeChecker::typeCheckDecl(Decl *D, bool LeaveBodyUnchecked) {
2609+
void TypeChecker::typeCheckDecl(Decl *D) {
26172610
auto *SF = D->getDeclContext()->getParentSourceFile();
2618-
DeclChecker declChecker(D->getASTContext(), SF);
2619-
declChecker.LeaveFunctionBodyUnchecked = LeaveBodyUnchecked;
2620-
declChecker.visit(D);
2611+
DeclChecker(D->getASTContext(), SF).visit(D);
26212612
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
323323
bool IsBraceStmtFromTopLevelDecl;
324324

325325
/// Skip type checking any elements inside 'BraceStmt', also this is
326-
/// propagated to DeclChecker and ConstraintSystem.
326+
/// propagated to ConstraintSystem.
327327
bool LeaveBraceStmtBodyUnchecked = false;
328328

329329
ASTContext &getASTContext() const { return Ctx; };
@@ -624,8 +624,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
624624
}
625625

626626
Stmt *visitDeferStmt(DeferStmt *DS) {
627-
TypeChecker::typeCheckDecl(
628-
DS->getTempDecl(), /*LeaveBodyUnchecked=*/LeaveBraceStmtBodyUnchecked);
627+
TypeChecker::typeCheckDecl(DS->getTempDecl());
629628

630629
Expr *theCall = DS->getCallExpr();
631630
TypeChecker::typeCheckExpression(theCall, DC);
@@ -1594,8 +1593,7 @@ void StmtChecker::typeCheckASTNode(ASTNode &node) {
15941593

15951594
// Type check the declaration.
15961595
if (auto *D = node.dyn_cast<Decl *>()) {
1597-
TypeChecker::typeCheckDecl(
1598-
D, /*LeaveBodyUnchecked=*/LeaveBraceStmtBodyUnchecked);
1596+
TypeChecker::typeCheckDecl(D);
15991597
return;
16001598
}
16011599

lib/Sema/TypeChecker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ Type typeCheckParameterDefault(Expr *&defaultValue, DeclContext *DC,
565565

566566
void typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD);
567567

568-
void typeCheckDecl(Decl *D, bool LeaveBodyUnchecked = false);
568+
void typeCheckDecl(Decl *D);
569569

570570
void addImplicitDynamicAttribute(Decl *D);
571571
void checkDeclAttributes(Decl *D);

test/IDE/complete_skipbody.swift

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token FUNCTIONBODY -debug-forbid-typecheck-prefix FORBIDDEN | %FileCheck %s
2+
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token LOCALFUNC_PARAMINIT -debug-forbid-typecheck-prefix FORBIDDEN | %FileCheck %s
23
// RUN: %swift-ide-test -code-completion -source-filename %s -code-completion-token TOPLEVEL -debug-forbid-typecheck-prefix FORBIDDEN | %FileCheck %s
34

45
struct FORBIDDEN_Struct {
@@ -33,6 +34,11 @@ func test(valueOptOpt: MyStruct??) {
3334
return
3435
}
3536

37+
func localFunc(_ x: Int) -> Int {
38+
let FORBIDDEN_unrelatedLocal = FORBIDDEN_Struct()
39+
return 1
40+
}
41+
3642
if (value.x == 1) {
3743
let unrelated2 = FORBIDDEN_Struct()
3844
switch value.x {
@@ -41,9 +47,15 @@ func test(valueOptOpt: MyStruct??) {
4147
_ = { xx in
4248
let unrelated4 = FORBIDDEN_Struct()
4349

44-
if xx == value.#^FUNCTIONBODY^# {
50+
if xx == localFunc(value.#^FUNCTIONBODY^#) {
51+
let unrelated5 = FORBIDDEN_Struct()
4552
return 1
4653
}
54+
55+
func innerFunc(x: Int = value.#^LOCALFUNC_PARAMINIT^#) {
56+
let unrelated6 = FORBIDDEN_Struct()
57+
}
58+
4759
return 0;
4860
} (x)
4961
default:

0 commit comments

Comments
 (0)