@@ -2514,10 +2514,6 @@ class AvailabilityWalker : public ASTWalker {
2514
2514
const ApplyExpr *call = nullptr ,
2515
2515
DeclAvailabilityFlags flags = None) const ;
2516
2516
2517
- bool diagnoseDeclAvailability (const ValueDecl *D, SourceRange R,
2518
- const ApplyExpr *call = nullptr ,
2519
- DeclAvailabilityFlags flags = None) const ;
2520
-
2521
2517
private:
2522
2518
bool diagnoseIncDecRemoval (const ValueDecl *D, SourceRange R,
2523
2519
const AvailableAttr *Attr) const ;
@@ -2581,7 +2577,8 @@ class AvailabilityWalker : public ASTWalker {
2581
2577
2582
2578
ValueDecl *D = E->getMember ().getDecl ();
2583
2579
// Diagnose for the member declaration itself.
2584
- if (diagnoseDeclAvailability (D, E->getNameLoc ().getSourceRange ()))
2580
+ if (diagnoseDeclAvailability (D, E->getNameLoc ().getSourceRange (),
2581
+ nullptr , Where))
2585
2582
return ;
2586
2583
2587
2584
// Diagnose for appropriate accessors, given the access context.
@@ -2682,9 +2679,13 @@ class AvailabilityWalker : public ASTWalker {
2682
2679
void diagAccessorAvailability (AccessorDecl *D, SourceRange ReferenceRange,
2683
2680
const DeclContext *ReferenceDC,
2684
2681
DeclAvailabilityFlags Flags) const {
2682
+ if (!D)
2683
+ return ;
2684
+
2685
2685
Flags &= DeclAvailabilityFlag::ForInout;
2686
2686
Flags |= DeclAvailabilityFlag::ContinueOnPotentialUnavailability;
2687
- if (diagnoseDeclAvailability (D, ReferenceRange, /* call*/ nullptr , Flags))
2687
+ if (diagnoseDeclAvailability (D, ReferenceRange, /* call*/ nullptr ,
2688
+ Where, Flags))
2688
2689
return ;
2689
2690
}
2690
2691
};
@@ -2700,7 +2701,14 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
2700
2701
return false ;
2701
2702
const ValueDecl *D = declRef.getDecl ();
2702
2703
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);
2704
2712
2705
2713
if (R.isValid ()) {
2706
2714
if (diagnoseSubstitutionMapAvailability (R.Start , declRef.getSubstitutions (),
@@ -2715,20 +2723,17 @@ AvailabilityWalker::diagnoseDeclRefAvailability(
2715
2723
// / Diagnose uses of unavailable declarations. Returns true if a diagnostic
2716
2724
// / was emitted.
2717
2725
bool
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
+
2721
2733
// Generic parameters are always available.
2722
2734
if (isa<GenericTypeParamDecl>(D))
2723
2735
return false ;
2724
2736
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
-
2732
2737
// Keep track if this is an accessor.
2733
2738
auto accessor = dyn_cast<AccessorDecl>(D);
2734
2739
@@ -2996,7 +3001,7 @@ class TypeReprAvailabilityWalker : public ASTWalker {
2996
3001
bool checkComponentIdentTypeRepr (ComponentIdentTypeRepr *ITR) {
2997
3002
if (auto *typeDecl = ITR->getBoundDecl ()) {
2998
3003
auto range = ITR->getNameLoc ().getSourceRange ();
2999
- if (diagnoseDeclAvailability (typeDecl, range, where, flags))
3004
+ if (diagnoseDeclAvailability (typeDecl, range, nullptr , where, flags))
3000
3005
return true ;
3001
3006
}
3002
3007
@@ -3190,20 +3195,6 @@ swift::diagnoseSubstitutionMapAvailability(SourceLoc loc,
3190
3195
return hadAnyIssues;
3191
3196
}
3192
3197
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
-
3207
3198
// / Should we warn that \p decl needs an explicit availability annotation
3208
3199
// / in -require-explicit-availability mode?
3209
3200
static bool declNeedsExplicitAvailability (const Decl *decl) {
0 commit comments