@@ -2293,7 +2293,7 @@ class AvailabilityWalker : public ASTWalker {
2293
2293
// DerivedConformanceRawRepresentable will do the right thing.
2294
2294
flags |= DeclAvailabilityFlag::AllowPotentiallyUnavailable;
2295
2295
2296
- diagAvailability (DR->getDecl (), DR->getSourceRange (),
2296
+ diagAvailability (DR->getDeclRef (), DR->getSourceRange (),
2297
2297
getEnclosingApplyExpr (), flags);
2298
2298
maybeDiagStorageAccess (DR->getDecl (), DR->getSourceRange (), DC);
2299
2299
}
@@ -2302,18 +2302,18 @@ class AvailabilityWalker : public ASTWalker {
2302
2302
return skipChildren ();
2303
2303
}
2304
2304
if (auto OCDR = dyn_cast<OtherConstructorDeclRefExpr>(E))
2305
- diagAvailability (OCDR->getDecl (),
2305
+ diagAvailability (OCDR->getDeclRef (),
2306
2306
OCDR->getConstructorLoc ().getSourceRange (),
2307
2307
getEnclosingApplyExpr ());
2308
2308
if (auto DMR = dyn_cast<DynamicMemberRefExpr>(E))
2309
- diagAvailability (DMR->getMember (). getDecl () ,
2309
+ diagAvailability (DMR->getMember (),
2310
2310
DMR->getNameLoc ().getSourceRange (),
2311
2311
getEnclosingApplyExpr ());
2312
2312
if (auto DS = dyn_cast<DynamicSubscriptExpr>(E))
2313
- diagAvailability (DS->getMember (). getDecl () , DS->getSourceRange ());
2313
+ diagAvailability (DS->getMember (), DS->getSourceRange ());
2314
2314
if (auto S = dyn_cast<SubscriptExpr>(E)) {
2315
2315
if (S->hasDecl ()) {
2316
- diagAvailability (S->getDecl (). getDecl () , S->getSourceRange ());
2316
+ diagAvailability (S->getDecl (), S->getSourceRange ());
2317
2317
maybeDiagStorageAccess (S->getDecl ().getDecl (), S->getSourceRange (), DC);
2318
2318
}
2319
2319
}
@@ -2328,7 +2328,7 @@ class AvailabilityWalker : public ASTWalker {
2328
2328
walkInOutExpr (IO);
2329
2329
return skipChildren ();
2330
2330
}
2331
-
2331
+
2332
2332
return visitChildren ();
2333
2333
}
2334
2334
@@ -2339,16 +2339,16 @@ class AvailabilityWalker : public ASTWalker {
2339
2339
return E;
2340
2340
}
2341
2341
2342
- bool diagAvailability (const ValueDecl *D , SourceRange R,
2342
+ bool diagAvailability (ConcreteDeclRef declRef , SourceRange R,
2343
2343
const ApplyExpr *call = nullptr ,
2344
- DeclAvailabilityFlags flags = None);
2344
+ DeclAvailabilityFlags flags = None) const ;
2345
2345
2346
2346
private:
2347
2347
bool diagnoseIncDecRemoval (const ValueDecl *D, SourceRange R,
2348
- const AvailableAttr *Attr);
2348
+ const AvailableAttr *Attr) const ;
2349
2349
bool diagnoseMemoryLayoutMigration (const ValueDecl *D, SourceRange R,
2350
2350
const AvailableAttr *Attr,
2351
- const ApplyExpr *call);
2351
+ const ApplyExpr *call) const ;
2352
2352
2353
2353
// / Walks up from a potential callee to the enclosing ApplyExpr.
2354
2354
const ApplyExpr *getEnclosingApplyExpr () const {
@@ -2502,10 +2502,7 @@ class AvailabilityWalker : public ASTWalker {
2502
2502
DeclAvailabilityFlags Flags) const {
2503
2503
Flags &= DeclAvailabilityFlag::ForInout;
2504
2504
Flags |= DeclAvailabilityFlag::ContinueOnPotentialUnavailability;
2505
- if (diagnoseDeclAvailability (D, TC,
2506
- const_cast <DeclContext*>(ReferenceDC),
2507
- ReferenceRange,
2508
- Flags))
2505
+ if (diagAvailability (D, ReferenceRange, /* call*/ nullptr , Flags))
2509
2506
return ;
2510
2507
}
2511
2508
};
@@ -2514,11 +2511,12 @@ class AvailabilityWalker : public ASTWalker {
2514
2511
// / Diagnose uses of unavailable declarations. Returns true if a diagnostic
2515
2512
// / was emitted.
2516
2513
bool
2517
- AvailabilityWalker::diagAvailability (const ValueDecl *D , SourceRange R,
2514
+ AvailabilityWalker::diagAvailability (ConcreteDeclRef declRef , SourceRange R,
2518
2515
const ApplyExpr *call,
2519
- DeclAvailabilityFlags Flags) {
2520
- if (!D )
2516
+ DeclAvailabilityFlags Flags) const {
2517
+ if (!declRef )
2521
2518
return false ;
2519
+ const ValueDecl *D = declRef.getDecl ();
2522
2520
2523
2521
if (auto *attr = AvailableAttr::isUnavailable (D)) {
2524
2522
if (diagnoseIncDecRemoval (D, R, attr))
@@ -2539,7 +2537,7 @@ AvailabilityWalker::diagAvailability(const ValueDecl *D, SourceRange R,
2539
2537
2540
2538
if (FragileKind)
2541
2539
if (R.isValid ())
2542
- if (TC.diagnoseInlinableDeclRef (R.Start , D , DC, *FragileKind,
2540
+ if (TC.diagnoseInlinableDeclRef (R.Start , declRef , DC, *FragileKind,
2543
2541
TreatUsableFromInlineAsPublic))
2544
2542
return true ;
2545
2543
@@ -2602,9 +2600,9 @@ static bool isIntegerOrFloatingPointType(Type ty, DeclContext *DC,
2602
2600
2603
2601
// / If this is a call to an unavailable ++ / -- operator, try to diagnose it
2604
2602
// / with a fixit hint and return true. If not, or if we fail, return false.
2605
- bool AvailabilityWalker::diagnoseIncDecRemoval ( const ValueDecl *D,
2606
- SourceRange R,
2607
- const AvailableAttr *Attr) {
2603
+ bool
2604
+ AvailabilityWalker::diagnoseIncDecRemoval ( const ValueDecl *D, SourceRange R,
2605
+ const AvailableAttr *Attr) const {
2608
2606
// We can only produce a fixit if we're talking about ++ or --.
2609
2607
bool isInc = D->getBaseName () == " ++" ;
2610
2608
if (!isInc && D->getBaseName () != " --" )
@@ -2664,10 +2662,11 @@ bool AvailabilityWalker::diagnoseIncDecRemoval(const ValueDecl *D,
2664
2662
2665
2663
// / If this is a call to an unavailable sizeof family function, diagnose it
2666
2664
// / with a fixit hint and return true. If not, or if we fail, return false.
2667
- bool AvailabilityWalker::diagnoseMemoryLayoutMigration (const ValueDecl *D,
2668
- SourceRange R,
2669
- const AvailableAttr *Attr,
2670
- const ApplyExpr *call) {
2665
+ bool
2666
+ AvailabilityWalker::diagnoseMemoryLayoutMigration (const ValueDecl *D,
2667
+ SourceRange R,
2668
+ const AvailableAttr *Attr,
2669
+ const ApplyExpr *call) const {
2671
2670
2672
2671
if (!D->getModuleContext ()->isStdlibModule ())
2673
2672
return false ;
@@ -2750,5 +2749,5 @@ bool swift::diagnoseDeclAvailability(const ValueDecl *Decl,
2750
2749
DeclAvailabilityFlags Flags)
2751
2750
{
2752
2751
AvailabilityWalker AW (TC, DC);
2753
- return AW.diagAvailability (Decl, R, nullptr , Flags);
2752
+ return AW.diagAvailability (const_cast <ValueDecl *>( Decl) , R, nullptr , Flags);
2754
2753
}
0 commit comments