static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS, const DeclContext *FromContext, LazyResolver *TypeResolver) { // Accessors are never visible directly in the source language. if (isa<AccessorDecl>(Member)) return false; if (TypeResolver) { TypeResolver->resolveDeclSignature(Member); } // Check access when relevant. if (!Member->getDeclContext()->isLocalContext() && !isa<GenericTypeParamDecl>(Member) && !isa<ParamDecl>(Member) && FromContext->getASTContext().LangOpts.EnableAccessControl) { if (!Member->isAccessibleFrom(FromContext)) return false; } if (auto *FD = dyn_cast<FuncDecl>(Member)) { // Cannot call static functions on non-metatypes. if (!LS.isOnMetatype() && FD->isStatic()) return false; // Otherwise, either call a function or curry it. return true; } if (auto *VD = dyn_cast<VarDecl>(Member)) { // Cannot use static properties on non-metatypes. if (!(LS.isQualified() && LS.isOnMetatype()) && VD->isStatic()) return false; // Cannot use instance properties on metatypes. if (LS.isOnMetatype() && !VD->isStatic() && !LS.isIncludingInstanceMembers()) return false; return true; } if (isa<EnumElementDecl>(Member)) { // Cannot reference enum elements on non-metatypes. if (!(LS.isQualified() && LS.isOnMetatype())) return false; } if (auto CD = dyn_cast<ConstructorDecl>(Member)) { // Constructors with stub implementations cannot be called in Swift. if (CD->hasStubImplementation()) return false; if (LS.isQualified() && LS.isOnSuperclass()) { // Cannot call initializers from a superclass, except for inherited // convenience initializers. return LS.isInheritsSuperclassInitializers() && CD->isInheritable(); } } if (isa<TypeDecl>(Member)) return areTypeDeclsVisibleInLookupMode(LS); return true; }
static bool areTypeDeclsVisibleInLookupMode(LookupState LS) { // Nested type declarations can be accessed only with unqualified lookup or // on metatypes. return !LS.isQualified() || LS.isOnMetatype(); }