Skip to content

Commit 5c03918

Browse files
committed
[NFC] Remove VarDecl guards on staticness checks
Fixes various places where we assume that only a VarDecl can be static so they operate on any AbstractStorageDecl instead. NFC until static subscripts are added.
1 parent 8bc1887 commit 5c03918

File tree

4 files changed

+9
-14
lines changed

4 files changed

+9
-14
lines changed

lib/AST/ASTPrinter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -893,8 +893,8 @@ class PrintAST : public ASTVisitor<PrintAST> {
893893
} // unnamed namespace
894894

895895
static StaticSpellingKind getCorrectStaticSpelling(const Decl *D) {
896-
if (auto *VD = dyn_cast<VarDecl>(D)) {
897-
return VD->getCorrectStaticSpelling();
896+
if (auto *ASD = dyn_cast<AbstractStorageDecl>(D)) {
897+
return ASD->getCorrectStaticSpelling();
898898
} else if (auto *PBD = dyn_cast<PatternBindingDecl>(D)) {
899899
return PBD->getCorrectStaticSpelling();
900900
} else if (auto *FD = dyn_cast<FuncDecl>(D)) {

lib/Index/Index.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -927,8 +927,7 @@ bool IndexSwiftASTWalker::reportPseudoAccessor(AbstractStorageDecl *D,
927927
Info.symInfo.Kind = SymbolKind::Function;
928928
if (D->getDeclContext()->isTypeContext()) {
929929
if (D->isStatic()) {
930-
if (isa<VarDecl>(D) &&
931-
cast<VarDecl>(D)->getCorrectStaticSpelling() == StaticSpellingKind::KeywordClass)
930+
if (D->getCorrectStaticSpelling() == StaticSpellingKind::KeywordClass)
932931
Info.symInfo.Kind = SymbolKind::ClassMethod;
933932
else
934933
Info.symInfo.Kind = SymbolKind::StaticMethod;

lib/Sema/CodeSynthesis.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,8 @@ static AccessorDecl *createGetterPrototype(AbstractStorageDecl *storage,
184184
auto *getterParams = buildIndexForwardingParamList(storage, {}, ctx);
185185

186186
SourceLoc staticLoc;
187-
if (auto var = dyn_cast<VarDecl>(storage)) {
188-
if (var->isStatic())
189-
staticLoc = var->getLoc();
190-
}
187+
if (storage->isStatic())
188+
staticLoc = storage->getLoc();
191189

192190
auto storageInterfaceType = storage->getValueInterfaceType();
193191

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -490,12 +490,10 @@ swift::matchWitness(
490490
} else if (auto *witnessASD = dyn_cast<AbstractStorageDecl>(witness)) {
491491
auto *reqASD = cast<AbstractStorageDecl>(req);
492492

493-
// If this is a property requirement, check that the static-ness matches.
494-
if (auto *vdWitness = dyn_cast<VarDecl>(witness)) {
495-
if (cast<VarDecl>(req)->isStatic() != vdWitness->isStatic())
496-
return RequirementMatch(witness, MatchKind::StaticNonStaticConflict);
497-
}
498-
493+
// Check that the static-ness matches.
494+
if (reqASD->isStatic() != witnessASD->isStatic())
495+
return RequirementMatch(witness, MatchKind::StaticNonStaticConflict);
496+
499497
// If the requirement is settable and the witness is not, reject it.
500498
if (req->isSettable(req->getDeclContext()) &&
501499
!witness->isSettable(witness->getDeclContext()))

0 commit comments

Comments
 (0)