Skip to content

Commit 0082ba5

Browse files
committed
Remove VarDecl::markInvalid
Inline the interface type reset into its callers and make sure they're also setting the invalid bit - which this was not doing before. Unfortunately, this is not enough to be able to simplify any part of var decl validation.
1 parent 28717ca commit 0082ba5

File tree

9 files changed

+32
-37
lines changed

9 files changed

+32
-37
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4809,8 +4809,6 @@ class VarDecl : public AbstractStorageDecl {
48094809
/// this will use archetypes.
48104810
Type getType() const;
48114811

4812-
void markInvalid();
4813-
48144812
/// Retrieve the source range of the variable type, or an invalid range if the
48154813
/// variable's type is not explicitly written in the source.
48164814
///

lib/AST/Decl.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5010,10 +5010,6 @@ Type VarDecl::getType() const {
50105010
return getDeclContext()->mapTypeIntoContext(getInterfaceType());
50115011
}
50125012

5013-
void VarDecl::markInvalid() {
5014-
setInterfaceType(ErrorType::get(getASTContext()));
5015-
}
5016-
50175013
/// Returns whether the var is settable in the specified context: this
50185014
/// is either because it is a stored var, because it has a custom setter, or
50195015
/// is a let member in an initializer.

lib/Sema/ConstraintSystem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ Type ConstraintSystem::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
823823
if (!var->isInvalid()) {
824824
TC.diagnose(var->getLoc(), diag::recursive_decl_reference,
825825
var->getDescriptiveKind(), var->getName());
826-
var->markInvalid();
826+
var->setInterfaceType(ErrorType::get(getASTContext()));
827827
}
828828
return ErrorType::get(TC.Context);
829829
}

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,7 +2824,7 @@ bool TypeChecker::typeCheckBinding(Pattern *&pattern, Expr *&initializer,
28242824
!var->getType()->hasError())
28252825
return;
28262826

2827-
var->markInvalid();
2827+
var->setInterfaceType(ErrorType::get(Context));
28282828
});
28292829
}
28302830

@@ -3033,7 +3033,7 @@ bool TypeChecker::typeCheckStmtCondition(StmtCondition &cond, DeclContext *dc,
30333033
// compute a type for.
30343034
if (var->hasInterfaceType() && !var->getType()->hasError())
30353035
return;
3036-
var->markInvalid();
3036+
var->setInterfaceType(ErrorType::get(Context));
30373037
});
30383038
};
30393039

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,7 +2459,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24592459
auto markVarAndPBDInvalid = [PBD, var] {
24602460
PBD->setInvalid();
24612461
var->setInvalid();
2462-
var->markInvalid();
2462+
var->setInterfaceType(ErrorType::get(var->getASTContext()));
24632463
};
24642464

24652465
// Properties with an opaque return type need an initializer to
@@ -4244,12 +4244,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
42444244
if (!PBD->isBeingValidated()) {
42454245
validatePatternBindingEntries(*this, PBD);
42464246
} else if (!VD->getNamingPattern()) {
4247-
// FIXME: This acts as a circularity breaker for overload resolution
4248-
// during pattern binding validation, which is allowed to lookup and
4249-
// find the very VarDecl attached to the binding it's trying to check.
4250-
// In order to tell it to back off, we surface an error type but don't
4251-
// set the interface type so a different caller can come along and
4252-
// do the right thing.
4247+
// FIXME: This acts as a circularity breaker.
42534248
return;
42544249
}
42554250

@@ -4260,7 +4255,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
42604255
}
42614256
} else if (!VD->getParentPatternStmt() && !VD->getParentVarDecl()) {
42624257
// No parent? That's an error.
4263-
VD->markInvalid();
4258+
VD->setInterfaceType(ErrorType::get(Context));
42644259
break;
42654260
}
42664261

@@ -4283,7 +4278,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
42834278

42844279
VD->getParentPattern()->setType(ErrorType::get(Context));
42854280
setBoundVarsTypeError(VD->getParentPattern(), Context);
4286-
VD->markInvalid();
4281+
VD->setInterfaceType(ErrorType::get(Context));
42874282
break;
42884283
}
42894284
}

lib/Sema/TypeCheckPattern.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ bool TypeChecker::typeCheckPattern(Pattern *P, DeclContext *dc,
806806
P->setType(ErrorType::get(Context));
807807
if (auto named = dyn_cast<NamedPattern>(P)) {
808808
if (auto var = named->getDecl()) {
809-
var->markInvalid();
809+
var->setInterfaceType(ErrorType::get(Context));
810+
var->setInvalid();
810811
}
811812
}
812813
return true;

lib/Sema/TypeCheckStmt.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,10 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
10641064

10651065
// If that failed, mark any variables binding pieces of the pattern
10661066
// as invalid to silence follow-on errors.
1067-
pattern->forEachVariable([&](VarDecl *VD) { VD->markInvalid(); });
1067+
pattern->forEachVariable([&](VarDecl *VD) {
1068+
VD->setInterfaceType(ErrorType::get(TC.Context));
1069+
VD->setInvalid();
1070+
});
10681071
}
10691072
labelItem.setPattern(pattern);
10701073

@@ -1140,8 +1143,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11401143
!vd->getType()->isEqual(initialCaseVarDecl->getType())) {
11411144
TC.diagnose(vd->getLoc(), diag::type_mismatch_multiple_pattern_list,
11421145
vd->getType(), initialCaseVarDecl->getType());
1143-
vd->markInvalid();
1144-
initialCaseVarDecl->markInvalid();
1146+
vd->setInterfaceType(ErrorType::get(TC.Context));
1147+
vd->setInvalid();
1148+
1149+
initialCaseVarDecl->setInterfaceType(ErrorType::get(TC.Context));
1150+
initialCaseVarDecl->setInvalid();
11451151
}
11461152

11471153
if (initialCaseVarDecl->isLet() == vd->isLet()) {
@@ -1161,8 +1167,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
11611167
if (foundVP)
11621168
diag.fixItReplace(foundVP->getLoc(),
11631169
initialCaseVarDecl->isLet() ? "let" : "var");
1164-
vd->markInvalid();
1165-
initialCaseVarDecl->markInvalid();
1170+
vd->setInterfaceType(ErrorType::get(TC.Context));
1171+
vd->setInvalid();
1172+
1173+
initialCaseVarDecl->setInterfaceType(ErrorType::get(TC.Context));
1174+
initialCaseVarDecl->setInvalid();
11661175
}
11671176
});
11681177

@@ -1229,8 +1238,11 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
12291238
TC.diagnose(previous->getLoc(),
12301239
diag::type_mismatch_fallthrough_pattern_list,
12311240
previous->getType(), expected->getType());
1232-
previous->markInvalid();
1233-
expected->markInvalid();
1241+
previous->setInterfaceType(ErrorType::get(TC.Context));
1242+
previous->setInvalid();
1243+
1244+
expected->setInterfaceType(ErrorType::get(TC.Context));
1245+
expected->setInvalid();
12341246
}
12351247

12361248
// Ok, we found our match. Make the previous fallthrough statement var
@@ -1465,7 +1477,8 @@ bool TypeChecker::typeCheckCatchPattern(CatchStmt *S, DeclContext *DC) {
14651477
// before we type-check the guard. (This will probably kill
14661478
// most of the type-checking, but maybe not.)
14671479
pattern->forEachVariable([&](VarDecl *var) {
1468-
var->markInvalid();
1480+
var->setInterfaceType(ErrorType::get(Context));
1481+
var->setInvalid();
14691482
});
14701483
}
14711484

lib/Sema/TypeCheckStorage.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ void swift::setBoundVarsTypeError(Pattern *pattern, ASTContext &ctx) {
4242
if (var->hasInterfaceType() && !var->getType()->hasError())
4343
return;
4444

45-
var->markInvalid();
45+
var->setInterfaceType(ErrorType::get(var->getASTContext()));
46+
var->setInvalid();
4647
});
4748
}
4849

test/decl/var/overload_cycle.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)