From 47951efcb9ecd2120a67b3517ef870eaee44bcaa Mon Sep 17 00:00:00 2001 From: Dmitri Hrybenko Date: Fri, 15 Nov 2013 01:32:20 +0000 Subject: [PATCH] Implement code completion support for static variables Swift SVN r10487 --- lib/AST/LookupVisibleDecls.cpp | 15 +++++++++++---- lib/IDE/CodeCompletion.cpp | 15 ++++++--------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/lib/AST/LookupVisibleDecls.cpp b/lib/AST/LookupVisibleDecls.cpp index c3c231ec072..18a994fc3f4 100644 --- a/lib/AST/LookupVisibleDecls.cpp +++ b/lib/AST/LookupVisibleDecls.cpp @@ -87,6 +87,17 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS) { if (!(LS.isQualified() && LS.isOnMetatype()) && FD->isStatic()) return false; } + if (auto *VD = dyn_cast(Member)) { + // Can not use static properties on non-metatypes. + if (!(LS.isQualified() && LS.isOnMetatype()) && VD->isStatic()) + return false; + + // Can not use instance properties on metatypes. + if (LS.isQualified() && LS.isOnMetatype() && !VD->isStatic()) + return false; + + return true; + } if (isa(Member)) { // Can not reference enum elements on non-metatypes. if (!(LS.isQualified() && LS.isOnMetatype())) @@ -96,10 +107,6 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS) { // Can not call constructors from a superclass. return false; } - if (LS.isQualified() && LS.isOnMetatype() && isa(Member)) { - // FIXME: static variables - return false; - } if (LS.isQualified() && !LS.isOnMetatype() && isa(Member)) { // Nested type declarations can be accessed only with unqualified lookup or // on metatypes. diff --git a/lib/IDE/CodeCompletion.cpp b/lib/IDE/CodeCompletion.cpp index 80c9de05948..2bf9e6f1c55 100644 --- a/lib/IDE/CodeCompletion.cpp +++ b/lib/IDE/CodeCompletion.cpp @@ -192,10 +192,10 @@ CodeCompletionResult::getCodeCompletionDeclKind(const Decl *D) { case DeclKind::Var: { auto DC = D->getDeclContext(); if (DC->isTypeContext()) { - // FIXME: Uncomment when static variables are implemented. - // if (D->isStatic()) - // return CodeCompletionDeclKind::StaticVar; - return CodeCompletionDeclKind::InstanceVar; + if (cast(D)->isStatic()) + return CodeCompletionDeclKind::StaticVar; + else + return CodeCompletionDeclKind::InstanceVar; } if (DC->isLocalContext()) return CodeCompletionDeclKind::LocalVar; @@ -896,11 +896,11 @@ public: StringRef Name = VD->getName().get(); assert(!Name.empty() && "name should not be empty"); - assert(!(InsideStaticMethod && + assert(VD->isStatic() || + !(InsideStaticMethod && VD->getDeclContext() == CurrentMethod->getDeclContext()) && "name lookup bug -- can not see an instance variable " "in a static function"); - // FIXME: static variables. CodeCompletionResultBuilder Builder( Sink, @@ -1220,9 +1220,6 @@ public: switch (Kind) { case LookupKind::ValueExpr: if (auto *VD = dyn_cast(D)) { - // Swift does not have class variables. - // FIXME: add code completion results when class variables are added. - assert(!ExprType->is() && "name lookup bug"); addVarDeclRef(VD, Reason); return; }