@@ -2037,7 +2037,8 @@ class VarDeclUsageChecker : public ASTWalker {
2037
2037
void operator =(const VarDeclUsageChecker &) = delete ;
2038
2038
2039
2039
public:
2040
- VarDeclUsageChecker (TypeChecker &TC, AbstractFunctionDecl *AFD) : Diags(TC.Diags) {
2040
+ VarDeclUsageChecker (AbstractFunctionDecl *AFD)
2041
+ : Diags(AFD->getASTContext ().Diags) {
2041
2042
// If this AFD is a setter, track the parameter and the getter for
2042
2043
// the containing property so if newValue isn't used but the getter is used
2043
2044
// an error can be reported.
@@ -2054,7 +2055,7 @@ class VarDeclUsageChecker : public ASTWalker {
2054
2055
2055
2056
VarDeclUsageChecker (DiagnosticEngine &Diags) : Diags(Diags) {}
2056
2057
2057
- VarDeclUsageChecker (TypeChecker &tc, VarDecl *vd) : Diags(tc .Diags) {
2058
+ VarDeclUsageChecker (VarDecl *vd) : Diags(vd-> getASTContext () .Diags) {
2058
2059
// Track a specific VarDecl
2059
2060
VarDecls[vd] = 0 ;
2060
2061
if (auto *childVd = vd->getCorrespondingCaseBodyVariable ().getPtrOrNull ()) {
@@ -2283,7 +2284,7 @@ class VarDeclUsageChecker : public ASTWalker {
2283
2284
// / An AST walker that determines the underlying type of an opaque return decl
2284
2285
// / from its associated function body.
2285
2286
class OpaqueUnderlyingTypeChecker : public ASTWalker {
2286
- TypeChecker &TC ;
2287
+ ASTContext &Ctx ;
2287
2288
AbstractFunctionDecl *Implementation;
2288
2289
OpaqueTypeDecl *OpaqueDecl;
2289
2290
BraceStmt *Body;
@@ -2292,11 +2293,10 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
2292
2293
bool HasInvalidReturn = false ;
2293
2294
2294
2295
public:
2295
- OpaqueUnderlyingTypeChecker (TypeChecker &TC,
2296
- AbstractFunctionDecl *Implementation,
2296
+ OpaqueUnderlyingTypeChecker (AbstractFunctionDecl *Implementation,
2297
2297
OpaqueTypeDecl *OpaqueDecl,
2298
2298
BraceStmt *Body)
2299
- : TC(TC ),
2299
+ : Ctx(Implementation-> getASTContext () ),
2300
2300
Implementation(Implementation),
2301
2301
OpaqueDecl(OpaqueDecl),
2302
2302
Body(Body)
@@ -2316,8 +2316,7 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
2316
2316
// If there are no candidates, then the body has no return statements, and
2317
2317
// we have nothing to infer the underlying type from.
2318
2318
if (Candidates.empty ()) {
2319
- TC.diagnose (Implementation->getLoc (),
2320
- diag::opaque_type_no_underlying_type_candidates);
2319
+ Implementation->diagnose (diag::opaque_type_no_underlying_type_candidates);
2321
2320
return ;
2322
2321
}
2323
2322
@@ -2339,12 +2338,12 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
2339
2338
}
2340
2339
2341
2340
if (mismatch) {
2342
- TC. diagnose ( Implementation->getLoc (),
2343
- diag::opaque_type_mismatched_underlying_type_candidates);
2341
+ Implementation->diagnose (
2342
+ diag::opaque_type_mismatched_underlying_type_candidates);
2344
2343
for (auto candidate : Candidates) {
2345
- TC .diagnose (candidate.first ->getLoc (),
2346
- diag::opaque_type_underlying_type_candidate_here,
2347
- candidate.second );
2344
+ Ctx. Diags .diagnose (candidate.first ->getLoc (),
2345
+ diag::opaque_type_underlying_type_candidate_here,
2346
+ candidate.second );
2348
2347
}
2349
2348
return ;
2350
2349
}
@@ -2356,9 +2355,9 @@ class OpaqueUnderlyingTypeChecker : public ASTWalker {
2356
2355
});
2357
2356
2358
2357
if (isSelfReferencing) {
2359
- TC .diagnose (Candidates.front ().first ->getLoc (),
2360
- diag::opaque_type_self_referential_underlying_type,
2361
- underlyingType);
2358
+ Ctx. Diags .diagnose (Candidates.front ().first ->getLoc (),
2359
+ diag::opaque_type_self_referential_underlying_type,
2360
+ underlyingType);
2362
2361
return ;
2363
2362
}
2364
2363
@@ -2885,14 +2884,14 @@ void VarDeclUsageChecker::handleIfConfig(IfConfigDecl *ICD) {
2885
2884
// / Apply the warnings managed by VarDeclUsageChecker to the top level
2886
2885
// / code declarations that haven't been checked yet.
2887
2886
void swift::
2888
- performTopLevelDeclDiagnostics (TypeChecker &TC, TopLevelCodeDecl *TLCD) {
2889
- VarDeclUsageChecker checker (TC.Diags );
2887
+ performTopLevelDeclDiagnostics (TopLevelCodeDecl *TLCD) {
2888
+ auto &ctx = TLCD->getDeclContext ()->getASTContext ();
2889
+ VarDeclUsageChecker checker (ctx.Diags );
2890
2890
TLCD->walk (checker);
2891
2891
}
2892
2892
2893
2893
// / Perform diagnostics for func/init/deinit declarations.
2894
- void swift::performAbstractFuncDeclDiagnostics (TypeChecker &TC,
2895
- AbstractFunctionDecl *AFD,
2894
+ void swift::performAbstractFuncDeclDiagnostics (AbstractFunctionDecl *AFD,
2896
2895
BraceStmt *body) {
2897
2896
assert (body && " Need a body to check" );
2898
2897
@@ -2902,17 +2901,17 @@ void swift::performAbstractFuncDeclDiagnostics(TypeChecker &TC,
2902
2901
2903
2902
// Check for unused variables, as well as variables that are could be
2904
2903
// declared as constants.
2905
- body->walk (VarDeclUsageChecker (TC, AFD));
2904
+ body->walk (VarDeclUsageChecker (AFD));
2906
2905
2907
2906
// If the function has an opaque return type, check the return expressions
2908
2907
// to determine the underlying type.
2909
2908
if (auto opaqueResultTy = AFD->getOpaqueResultTypeDecl ()) {
2910
- OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy, body).check ();
2909
+ OpaqueUnderlyingTypeChecker (AFD, opaqueResultTy, body).check ();
2911
2910
} else if (auto accessor = dyn_cast<AccessorDecl>(AFD)) {
2912
2911
if (accessor->isGetter ()) {
2913
2912
if (auto opaqueResultTy
2914
2913
= accessor->getStorage ()->getOpaqueResultTypeDecl ()) {
2915
- OpaqueUnderlyingTypeChecker (TC, AFD, opaqueResultTy, body).check ();
2914
+ OpaqueUnderlyingTypeChecker (AFD, opaqueResultTy, body).check ();
2916
2915
}
2917
2916
}
2918
2917
}
0 commit comments