@@ -2514,10 +2514,6 @@ class AvailabilityWalker : public ASTWalker {
25142514 const ApplyExpr *call = nullptr ,
25152515 DeclAvailabilityFlags flags = None) const ;
25162516
2517- bool diagnoseDeclAvailability (const ValueDecl *D, SourceRange R,
2518- const ApplyExpr *call = nullptr ,
2519- DeclAvailabilityFlags flags = None) const ;
2520-
25212517private:
25222518 bool diagnoseIncDecRemoval (const ValueDecl *D, SourceRange R,
25232519 const AvailableAttr *Attr) const ;
@@ -2581,7 +2577,8 @@ class AvailabilityWalker : public ASTWalker {
25812577
25822578 ValueDecl *D = E->getMember ().getDecl ();
25832579 // Diagnose for the member declaration itself.
2584- if (diagnoseDeclAvailability (D, E->getNameLoc ().getSourceRange ()))
2580+ if (diagnoseDeclAvailability (D, E->getNameLoc ().getSourceRange (),
2581+ nullptr , Where))
25852582 return ;
25862583
25872584 // Diagnose for appropriate accessors, given the access context.
@@ -2682,9 +2679,13 @@ class AvailabilityWalker : public ASTWalker {
26822679 void diagAccessorAvailability (AccessorDecl *D, SourceRange ReferenceRange,
26832680 const DeclContext *ReferenceDC,
26842681 DeclAvailabilityFlags Flags) const {
2682+ if (!D)
2683+ return ;
2684+
26852685 Flags &= DeclAvailabilityFlag::ForInout;
26862686 Flags |= DeclAvailabilityFlag::ContinueOnPotentialUnavailability;
2687- if (diagnoseDeclAvailability (D, ReferenceRange, /* call*/ nullptr , Flags))
2687+ if (diagnoseDeclAvailability (D, ReferenceRange, /* call*/ nullptr ,
2688+ Where, Flags))
26882689 return ;
26892690 }
26902691};
@@ -2700,7 +2701,14 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
27002701 return false ;
27012702 const ValueDecl *D = declRef.getDecl ();
27022703
2703- diagnoseDeclAvailability (D, R, call, Flags);
2704+ if (auto *attr = AvailableAttr::isUnavailable (D)) {
2705+ if (diagnoseIncDecRemoval (D, R, attr))
2706+ return true ;
2707+ if (call && diagnoseMemoryLayoutMigration (D, R, attr, call))
2708+ return true ;
2709+ }
2710+
2711+ diagnoseDeclAvailability (D, R, call, Where, Flags);
27042712
27052713 if (R.isValid ()) {
27062714 if (diagnoseSubstitutionMapAvailability (R.Start , declRef.getSubstitutions (),
@@ -2715,20 +2723,17 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
27152723// / Diagnose uses of unavailable declarations. Returns true if a diagnostic
27162724// / was emitted.
27172725bool
2718- AvailabilityWalker::diagnoseDeclAvailability (
2719- const ValueDecl *D, SourceRange R, const ApplyExpr *call,
2720- DeclAvailabilityFlags Flags) const {
2726+ swift::diagnoseDeclAvailability (const ValueDecl *D,
2727+ SourceRange R,
2728+ const ApplyExpr *call,
2729+ ExportContext Where,
2730+ DeclAvailabilityFlags Flags) {
2731+ assert (!Where.isImplicit ());
2732+
27212733 // Generic parameters are always available.
27222734 if (isa<GenericTypeParamDecl>(D))
27232735 return false ;
27242736
2725- if (auto *attr = AvailableAttr::isUnavailable (D)) {
2726- if (diagnoseIncDecRemoval (D, R, attr))
2727- return true ;
2728- if (call && diagnoseMemoryLayoutMigration (D, R, attr, call))
2729- return true ;
2730- }
2731-
27322737 // Keep track if this is an accessor.
27332738 auto accessor = dyn_cast<AccessorDecl>(D);
27342739
@@ -2996,7 +3001,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
29963001 bool checkComponentIdentTypeRepr (ComponentIdentTypeRepr *ITR) {
29973002 if (auto *typeDecl = ITR->getBoundDecl ()) {
29983003 auto range = ITR->getNameLoc ().getSourceRange ();
2999- if (diagnoseDeclAvailability (typeDecl, range, where, flags))
3004+ if (diagnoseDeclAvailability (typeDecl, range, nullptr , where, flags))
30003005 return true ;
30013006 }
30023007
@@ -3190,20 +3195,6 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
31903195 return hadAnyIssues;
31913196}
31923197
3193- // / Run the Availability-diagnostics algorithm otherwise used in an expr
3194- // / context, but for non-expr contexts such as TypeDecls referenced from
3195- // / TypeReprs.
3196- bool swift::diagnoseDeclAvailability (const ValueDecl *Decl,
3197- SourceRange R,
3198- ExportContext Where,
3199- DeclAvailabilityFlags Flags)
3200- {
3201- assert (!Where.isImplicit ());
3202- AvailabilityWalker AW (Where);
3203- return AW.diagnoseDeclAvailability (const_cast <ValueDecl *>(Decl), R,
3204- nullptr , Flags);
3205- }
3206-
32073198// / Should we warn that \p decl needs an explicit availability annotation
32083199// / in -require-explicit-availability mode?
32093200static bool declNeedsExplicitAvailability (const Decl *decl) {
0 commit comments