Skip to content

Commit 66a07ba

Browse files
committed
[Diagnostics] Switch getContextualType* to use TypedNode
1 parent 71ab19b commit 66a07ba

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ ValueDecl *RequirementFailure::getDeclRef() const {
249249
};
250250

251251
if (isFromContextualType())
252-
return getAffectedDeclFromType(
253-
getContextualType(getLocator()->getAnchor()));
252+
return getAffectedDeclFromType(getContextualType(getRawAnchor()));
254253

255254
if (auto overload = getCalleeOverloadChoiceIfAvailable(getLocator())) {
256255
// If there is a declaration associated with this
@@ -2266,8 +2265,7 @@ bool ContextualFailure::diagnoseConversionToNil() const {
22662265
emitDiagnostic(*diagnostic, getToType());
22672266

22682267
if (CTP == CTP_Initialization) {
2269-
auto *rawAnchor = getRawAnchor().get<const Expr *>();
2270-
auto *patternTR = getContextualTypeLoc(rawAnchor).getTypeRepr();
2268+
auto *patternTR = getContextualTypeLoc(getRawAnchor()).getTypeRepr();
22712269
if (!patternTR)
22722270
return true;
22732271

@@ -2993,8 +2991,7 @@ bool TupleContextualFailure::diagnoseAsError() {
29932991
auto purpose = getContextualTypePurpose();
29942992
if (isNumElementsMismatch())
29952993
diagnostic = diag::tuple_types_not_convertible_nelts;
2996-
else if ((purpose == CTP_Initialization) &&
2997-
!getContextualType(getAnchor().get<const Expr *>()))
2994+
else if ((purpose == CTP_Initialization) && !getContextualType(getAnchor()))
29982995
diagnostic = diag::tuple_types_not_convertible;
29992996
else if (auto diag = getDiagnosticFor(purpose, getToType()))
30002997
diagnostic = *diag;
@@ -3718,7 +3715,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() {
37183715
}
37193716

37203717
// Determine the contextual type of the expression
3721-
Type contextualType = getContextualType(getRawAnchor().get<const Expr *>());
3718+
Type contextualType = getContextualType(getRawAnchor());
37223719
// Try to provide a fix-it that only contains a '.'
37233720
if (contextualType && baseTy->isEqual(contextualType)) {
37243721
Diag->fixItInsert(loc, ".");
@@ -3893,9 +3890,8 @@ bool MissingArgumentsFailure::diagnoseAsError() {
38933890
// let _: (Int) -> Void = foo
38943891
// ```
38953892
if (locator->isLastElement<LocatorPathElt::ContextualType>()) {
3896-
emitDiagnostic(
3897-
diag::cannot_convert_initializer_value, getType(anchor),
3898-
resolveType(getContextualType(getAnchor().get<const Expr *>())));
3893+
emitDiagnostic(diag::cannot_convert_initializer_value, getType(anchor),
3894+
resolveType(getContextualType(getAnchor())));
38993895
// TODO: It would be great so somehow point out which arguments are missing.
39003896
return true;
39013897
}
@@ -4941,11 +4937,10 @@ bool CollectionElementContextualFailure::diagnoseAsError() {
49414937
}
49424938

49434939
if (locator->isForSequenceElementType()) {
4944-
auto &cs = getConstraintSystem();
49454940
// If this is a conversion failure related to binding of `for-each`
49464941
// statement it has to be diagnosed as pattern match if there are
49474942
// holes present in the contextual type.
4948-
if (cs.getContextualTypePurpose(getAnchor().get<const Expr *>()) ==
4943+
if (getContextualTypePurpose(getAnchor()) ==
49494944
ContextualTypePurpose::CTP_ForEachStmt &&
49504945
contextualType->hasHole()) {
49514946
diagnostic.emplace(emitDiagnostic(
@@ -5409,7 +5404,7 @@ bool InOutConversionFailure::diagnoseAsError() {
54095404
argApplyInfo->getArgType(), argApplyInfo->getParamType());
54105405
} else {
54115406
assert(locator->findLast<LocatorPathElt::ContextualType>());
5412-
auto *anchor = getAnchor().get<const Expr *>();
5407+
auto anchor = getAnchor();
54135408
auto contextualType = getContextualType(anchor);
54145409
auto purpose = getContextualTypePurpose();
54155410
auto diagnostic = getDiagnosticFor(purpose, contextualType);

lib/Sema/CSDiagnostics.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ class FailureDiagnostic {
118118
return S.getConstraintSystem();
119119
}
120120

121-
Type getContextualType(Expr *anchor) const {
121+
Type getContextualType(TypedNode anchor) const {
122122
auto &cs = getConstraintSystem();
123-
return cs.getContextualType(anchor);
123+
return cs.getContextualType(anchor.get<const Expr *>());
124124
}
125125

126-
TypeLoc getContextualTypeLoc(Expr *anchor) const {
126+
TypeLoc getContextualTypeLoc(TypedNode anchor) const {
127127
auto &cs = getConstraintSystem();
128-
return cs.getContextualTypeLoc(anchor);
128+
return cs.getContextualTypeLoc(anchor.get<const Expr *>());
129129
}
130130

131-
ContextualTypePurpose getContextualTypePurpose(Expr *anchor) const {
131+
ContextualTypePurpose getContextualTypePurpose(TypedNode anchor) const {
132132
auto &cs = getConstraintSystem();
133-
return cs.getContextualTypePurpose(anchor);
133+
return cs.getContextualTypePurpose(anchor.get<const Expr *>());
134134
}
135135

136136
DeclContext *getDC() const {

0 commit comments

Comments
 (0)