@@ -117,7 +117,7 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
117
117
118
118
template <typename ...ArgTypes>
119
119
InFlightDiagnostic diagnose (ArgTypes &&...Args) {
120
- return CS.TC .diagnose (std::forward<ArgTypes>(Args)...);
120
+ return CS.getASTContext (). Diags .diagnose (std::forward<ArgTypes>(Args)...);
121
121
}
122
122
123
123
// / Attempt to diagnose a failure without taking into account the specific
@@ -1270,7 +1270,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
1270
1270
1271
1271
// If it failed and diagnosed something, then we're done.
1272
1272
if (!exprType)
1273
- return CS.TC .Diags .hadAnyError ();
1273
+ return CS.getASTContext () .Diags .hadAnyError ();
1274
1274
1275
1275
// If we don't have a type for the expression, then we cannot use it in
1276
1276
// conversion constraint diagnostic generation. If the types match, then it
@@ -1647,14 +1647,14 @@ static DeclName getBaseName(DeclContext *context) {
1647
1647
};
1648
1648
1649
1649
static void emitFixItForExplicitlyQualifiedReference (
1650
- TypeChecker &tc , UnresolvedDotExpr *UDE,
1650
+ DiagnosticEngine &de , UnresolvedDotExpr *UDE,
1651
1651
decltype (diag::fix_unqualified_access_top_level) diag, DeclName baseName,
1652
1652
DescriptiveDeclKind kind) {
1653
1653
auto name = baseName.getBaseIdentifier ();
1654
1654
SmallString<32 > namePlusDot = name.str ();
1655
1655
namePlusDot.push_back (' .' );
1656
1656
1657
- tc .diagnose (UDE->getLoc (), diag, namePlusDot, kind, name)
1657
+ de .diagnose (UDE->getLoc (), diag, namePlusDot, kind, name)
1658
1658
.fixItInsert (UDE->getStartLoc (), namePlusDot);
1659
1659
}
1660
1660
@@ -1678,14 +1678,16 @@ void ConstraintSystem::diagnoseDeprecatedConditionalConformanceOuterAccess(
1678
1678
? choiceParentDecl->getDescriptiveKind ()
1679
1679
: DescriptiveDeclKind::Module;
1680
1680
1681
- TC.diagnose (UDE->getLoc (),
1681
+ auto &DE = getASTContext ().Diags ;
1682
+ DE.diagnose (UDE->getLoc (),
1682
1683
diag::warn_deprecated_conditional_conformance_outer_access,
1683
1684
UDE->getName (), choiceKind, choiceParentKind, choiceBaseName,
1684
1685
innerChoice->getDescriptiveKind (),
1685
1686
innerParentDecl->getDescriptiveKind (), innerBaseName);
1686
1687
1687
1688
emitFixItForExplicitlyQualifiedReference (
1688
- TC, UDE, diag::fix_deprecated_conditional_conformance_outer_access,
1689
+ getASTContext ().Diags , UDE,
1690
+ diag::fix_deprecated_conditional_conformance_outer_access,
1689
1691
choiceBaseName, choiceKind);
1690
1692
}
1691
1693
@@ -1705,7 +1707,7 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
1705
1707
if (CCI.empty () || !CCI[0 ].getDecl ())
1706
1708
return false ;
1707
1709
1708
- auto &TC = CS.TC ;
1710
+ auto &ctx = CS.getASTContext () ;
1709
1711
// Call expression is formed as 'foo.bar' where 'foo' might be an
1710
1712
// implicit "Self" reference, such use wouldn't provide good diagnostics
1711
1713
// for situations where instance members have equal names to functions in
@@ -1719,7 +1721,7 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
1719
1721
return false ;
1720
1722
1721
1723
auto baseDecl = baseExpr->getDecl ();
1722
- if (!baseExpr->isImplicit () || baseDecl->getFullName () != TC. Context .Id_self )
1724
+ if (!baseExpr->isImplicit () || baseDecl->getFullName () != ctx .Id_self )
1723
1725
return false ;
1724
1726
1725
1727
// Our base expression is an implicit 'self.' reference e.g.
@@ -1837,21 +1839,23 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
1837
1839
auto baseName = getBaseName (choice->getDeclContext ());
1838
1840
1839
1841
auto origCandidate = CCI[0 ].getDecl ();
1840
- TC.diagnose (UDE->getLoc (), diagnostic, UDE->getName (),
1841
- origCandidate->getDescriptiveKind (),
1842
- origCandidate->getFullName (), choice->getDescriptiveKind (),
1843
- choice->getFullName (), baseKind, baseName);
1842
+ ctx.Diags .diagnose (UDE->getLoc (), diagnostic, UDE->getName (),
1843
+ origCandidate->getDescriptiveKind (),
1844
+ origCandidate->getFullName (),
1845
+ choice->getDescriptiveKind (),
1846
+ choice->getFullName (), baseKind, baseName);
1844
1847
1845
1848
auto topLevelDiag = diag::fix_unqualified_access_top_level;
1846
1849
if (baseKind == DescriptiveDeclKind::Module)
1847
1850
topLevelDiag = diag::fix_unqualified_access_top_level_multi;
1848
1851
1849
- emitFixItForExplicitlyQualifiedReference (TC, UDE, topLevelDiag, baseName,
1852
+ emitFixItForExplicitlyQualifiedReference (ctx.Diags , UDE, topLevelDiag,
1853
+ baseName,
1850
1854
choice->getDescriptiveKind ());
1851
1855
1852
1856
for (auto &candidate : calleeInfo.candidates ) {
1853
1857
if (auto decl = candidate.getDecl ())
1854
- TC .diagnose (decl, diag::decl_declared_here, decl->getFullName ());
1858
+ ctx. Diags .diagnose (decl, diag::decl_declared_here, decl->getFullName ());
1855
1859
}
1856
1860
1857
1861
return true ;
@@ -1912,7 +1916,6 @@ bool FailureDiagnosis::diagnoseImplicitSelfErrors(
1912
1916
}
1913
1917
1914
1918
class ArgumentMatcher : public MatchCallArgumentListener {
1915
- TypeChecker &TC;
1916
1919
Expr *ArgExpr;
1917
1920
ArrayRef<AnyFunctionType::Param> &Parameters;
1918
1921
const ParameterListInfo &ParamInfo;
@@ -1934,7 +1937,7 @@ class ArgumentMatcher : public MatchCallArgumentListener {
1934
1937
const ParameterListInfo ¶mInfo,
1935
1938
SmallVectorImpl<AnyFunctionType::Param> &args,
1936
1939
CalleeCandidateInfo &CCI, bool isSubscript)
1937
- : TC(CCI.CS.TC), ArgExpr(argExpr), Parameters(params),
1940
+ : ArgExpr(argExpr), Parameters(params),
1938
1941
ParamInfo (paramInfo), Arguments(args), CandidateInfo(CCI),
1939
1942
IsSubscript(isSubscript) {}
1940
1943
@@ -1950,7 +1953,8 @@ class ArgumentMatcher : public MatchCallArgumentListener {
1950
1953
assert (!newNames.empty () && " No arguments were re-labeled" );
1951
1954
1952
1955
// Let's diagnose labeling problem but only related to corrected ones.
1953
- if (diagnoseArgumentLabelError (TC.Context , ArgExpr, newNames, IsSubscript))
1956
+ if (diagnoseArgumentLabelError (CandidateInfo.CS .getASTContext (), ArgExpr,
1957
+ newNames, IsSubscript))
1954
1958
Diagnosed = true ;
1955
1959
1956
1960
return true ;
@@ -1981,7 +1985,6 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
1981
1985
return false ;
1982
1986
1983
1987
auto candidate = CCI[0 ];
1984
- auto &TC = CCI.CS .TC ;
1985
1988
1986
1989
if (!candidate.hasParameters ())
1987
1990
return false ;
@@ -2015,7 +2018,7 @@ diagnoseSingleCandidateFailures(CalleeCandidateInfo &CCI, Expr *fnExpr,
2015
2018
};
2016
2019
Expr *innerE = getInnerExpr (argExpr);
2017
2020
2018
- InFlightDiagnostic diag = TC .diagnose (
2021
+ InFlightDiagnostic diag = CCI. CS . getASTContext (). Diags .diagnose (
2019
2022
fnExpr->getLoc (),
2020
2023
diag::invalid_initialization_parameter_same_type, resTy);
2021
2024
diag.highlight ((innerE ? innerE : argExpr)->getSourceRange ());
@@ -2063,13 +2066,14 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
2063
2066
ArrayRef<Identifier> argLabels) {
2064
2067
if (auto *MTT = CS.getType (fnExpr)->getAs <MetatypeType>()) {
2065
2068
auto instTy = MTT->getInstanceType ();
2069
+ auto &DE = CS.getASTContext ().Diags ;
2066
2070
if (instTy->getAnyNominal ()) {
2067
2071
// If we are invoking a constructor on a nominal type and there are
2068
2072
// absolutely no candidates, then they must all be private.
2069
2073
if (CCI.empty () || (CCI.size () == 1 && CCI.candidates [0 ].getDecl () &&
2070
2074
isa<ProtocolDecl>(CCI.candidates [0 ].getDecl ()))) {
2071
- CS. TC .diagnose (fnExpr->getLoc (), diag::no_accessible_initializers,
2072
- instTy);
2075
+ DE .diagnose (fnExpr->getLoc (), diag::no_accessible_initializers,
2076
+ instTy);
2073
2077
return true ;
2074
2078
}
2075
2079
// continue below
@@ -2078,9 +2082,9 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
2078
2082
// is malformed.
2079
2083
SourceRange initExprRange (fnExpr->getSourceRange ().Start ,
2080
2084
argExpr->getSourceRange ().End );
2081
- CS. TC .diagnose (fnExpr->getLoc (), instTy->isExistentialType () ?
2082
- diag::construct_protocol_by_name :
2083
- diag::non_nominal_no_initializers, instTy)
2085
+ DE .diagnose (fnExpr->getLoc (), instTy->isExistentialType () ?
2086
+ diag::construct_protocol_by_name :
2087
+ diag::non_nominal_no_initializers, instTy)
2084
2088
.highlight (initExprRange);
2085
2089
return true ;
2086
2090
}
@@ -2362,8 +2366,8 @@ static bool diagnoseClosureExplicitParameterMismatch(
2362
2366
continue ;
2363
2367
2364
2368
if (!CS.TC .isConvertibleTo (argType, paramType, CS.DC )) {
2365
- CS.TC . diagnose (loc, diag::types_not_convertible, false , paramType ,
2366
- argType);
2369
+ CS.getASTContext (). Diags . diagnose (loc, diag::types_not_convertible,
2370
+ false , paramType, argType);
2367
2371
return true ;
2368
2372
}
2369
2373
}
@@ -2478,9 +2482,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
2478
2482
auto processor = [&](Type resultType, Type expectedResultType) -> bool {
2479
2483
if (resultType && expectedResultType) {
2480
2484
if (!resultType->isEqual (expectedResultType)) {
2481
- CS.TC .diagnose (closureExpr->getEndLoc (),
2482
- diag::cannot_convert_closure_result, resultType,
2483
- expectedResultType);
2485
+ auto &DE = CS.getASTContext ().Diags ;
2486
+ DE.diagnose (closureExpr->getEndLoc (),
2487
+ diag::cannot_convert_closure_result, resultType,
2488
+ expectedResultType);
2484
2489
return true ;
2485
2490
}
2486
2491
@@ -2650,7 +2655,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
2650
2655
// possible.
2651
2656
fnExpr = typeCheckChildIndependently (callExpr->getFn ());
2652
2657
if (!fnExpr) {
2653
- return CS.TC .Diags .hadAnyError ();
2658
+ return CS.getASTContext () .Diags .hadAnyError ();
2654
2659
}
2655
2660
}
2656
2661
@@ -3298,7 +3303,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
3298
3303
}
3299
3304
3300
3305
// Coerce parameter types here only if there are no unresolved
3301
- CS. TC . coerceParameterListToType (params, CE, fnType);
3306
+ TypeChecker:: coerceParameterListToType (params, CE, fnType);
3302
3307
expectedResultType = fnType->getResult ();
3303
3308
}
3304
3309
@@ -3525,19 +3530,18 @@ bool FailureDiagnosis::visitDictionaryExpr(DictionaryExpr *E) {
3525
3530
// / _ColorLiteralType), suggest that the user import the appropriate module for
3526
3531
// / the target.
3527
3532
bool FailureDiagnosis::visitObjectLiteralExpr (ObjectLiteralExpr *E) {
3528
- auto &TC = CS.getTypeChecker ();
3529
-
3530
3533
// Type check the argument first.
3531
3534
auto protocol = TypeChecker::getLiteralProtocol (CS.getASTContext (), E);
3532
3535
if (!protocol)
3533
3536
return false ;
3534
- DeclName constrName = TC.getObjectLiteralConstructorName (E);
3537
+ auto constrName =
3538
+ TypeChecker::getObjectLiteralConstructorName (CS.getASTContext (), E);
3535
3539
assert (constrName);
3536
3540
auto *constr = dyn_cast_or_null<ConstructorDecl>(
3537
3541
protocol->getSingleRequirement (constrName));
3538
3542
if (!constr)
3539
3543
return false ;
3540
- auto paramType = TC. getObjectLiteralParameterType (E, constr);
3544
+ auto paramType = TypeChecker:: getObjectLiteralParameterType (E, constr);
3541
3545
if (!typeCheckChildIndependently (
3542
3546
E->getArg (), paramType, CTP_CallArgument))
3543
3547
return true ;
@@ -3580,11 +3584,11 @@ bool FailureDiagnosis::visitObjectLiteralExpr(ObjectLiteralExpr *E) {
3580
3584
3581
3585
// Emit the diagnostic.
3582
3586
const auto plainName = E->getLiteralKindPlainName ();
3583
- TC .diagnose (E->getLoc (), diag::object_literal_default_type_missing,
3584
- plainName);
3587
+ Ctx. Diags .diagnose (E->getLoc (), diag::object_literal_default_type_missing,
3588
+ plainName);
3585
3589
if (!importModule.empty ()) {
3586
- TC .diagnose (E->getLoc (), diag::object_literal_resolve_import,
3587
- importModule, importDefaultTypeName, plainName);
3590
+ Ctx. Diags .diagnose (E->getLoc (), diag::object_literal_resolve_import,
3591
+ importModule, importDefaultTypeName, plainName);
3588
3592
}
3589
3593
return true ;
3590
3594
}
0 commit comments