@@ -75,12 +75,14 @@ std::pair<Expr *, bool> FailureDiagnostic::computeAnchor() const {
75
75
return {anchor, !resolved->getPath ().empty ()};
76
76
}
77
77
78
- Type FailureDiagnostic::getType (Expr *expr) const {
79
- return resolveType (CS.getType (expr));
78
+ Type FailureDiagnostic::getType (Expr *expr, bool wantRValue) const {
79
+ return resolveType (CS.getType (expr), /* reconstituteSugar=*/ false ,
80
+ wantRValue);
80
81
}
81
82
82
- Type FailureDiagnostic::getType (const TypeLoc &loc) const {
83
- return resolveType (CS.getType (loc));
83
+ Type FailureDiagnostic::getType (const TypeLoc &loc, bool wantRValue) const {
84
+ return resolveType (CS.getType (loc), /* reconstituteSugar=*/ false ,
85
+ wantRValue);
84
86
}
85
87
86
88
template <typename ... ArgTypes>
@@ -248,7 +250,6 @@ FailureDiagnostic::getFunctionArgApplyInfo(ConstraintLocator *locator) const {
248
250
// Try to resolve the function type by loading lvalues and looking through
249
251
// optional types, which can occur for expressions like `fn?(5)`.
250
252
auto *fnType = resolveType (rawFnType)
251
- ->getRValueType ()
252
253
->lookThroughAllOptionalTypes ()
253
254
->getAs <FunctionType>();
254
255
if (!fnType)
@@ -1077,7 +1078,7 @@ bool MemberAccessOnOptionalBaseFailure::diagnoseAsError() {
1077
1078
return false ;
1078
1079
1079
1080
auto *anchor = getAnchor ();
1080
- auto baseType = getType (anchor)-> getRValueType () ;
1081
+ auto baseType = getType (anchor);
1081
1082
bool resultIsOptional = ResultTypeIsOptional;
1082
1083
1083
1084
// If we've resolved the member overload to one that returns an optional
@@ -1229,7 +1230,7 @@ bool MissingOptionalUnwrapFailure::diagnoseAsError() {
1229
1230
}
1230
1231
1231
1232
emitDiagnostic (tryExpr->getTryLoc (), diag::missing_unwrap_optional_try,
1232
- getType (anchor)-> getRValueType () )
1233
+ getType (anchor))
1233
1234
.fixItReplace ({tryExpr->getTryLoc (), tryExpr->getQuestionLoc ()},
1234
1235
" try!" );
1235
1236
return true ;
@@ -1399,7 +1400,7 @@ bool RValueTreatedAsLValueFailure::diagnoseAsError() {
1399
1400
1400
1401
if (resolvedOverload->Choice .getKind () ==
1401
1402
OverloadChoiceKind::KeyPathDynamicMemberLookup) {
1402
- if (!getType (member->getBase ())->hasLValueType ())
1403
+ if (!getType (member->getBase (), /* wantRValue= */ false )->hasLValueType ())
1403
1404
subElementDiagID =
1404
1405
diag::assignment_dynamic_property_has_immutable_base;
1405
1406
}
@@ -2299,7 +2300,7 @@ bool ContextualFailure::diagnoseYieldByReferenceMismatch() const {
2299
2300
return false ;
2300
2301
2301
2302
auto *anchor = getAnchor ();
2302
- auto exprType = getType (anchor);
2303
+ auto exprType = getType (anchor, /* wantRValue= */ false );
2303
2304
auto contextualType = getToType ();
2304
2305
2305
2306
if (auto exprLV = exprType->getAs <LValueType>()) {
@@ -5163,7 +5164,7 @@ bool ArgumentMismatchFailure::diagnoseAsError() {
5163
5164
// let's match up its element type to the argument to see whether
5164
5165
// it would be appropriate to suggest adding `&`.
5165
5166
auto *argExpr = getAnchor ();
5166
- if (getType (argExpr)->is <LValueType>()) {
5167
+ if (getType (argExpr, /* wantRValue= */ false )->is <LValueType>()) {
5167
5168
auto elementTy = paramType->getAnyPointerElementType ();
5168
5169
if (elementTy && argType->isEqual (elementTy)) {
5169
5170
diag.fixItInsert (argExpr->getStartLoc (), " &" );
@@ -5199,8 +5200,8 @@ bool ArgumentMismatchFailure::diagnoseUseOfReferenceEqualityOperator() const {
5199
5200
5200
5201
auto name = *getOperatorName (binaryOp->getFn ());
5201
5202
5202
- auto lhsType = getType (lhs)-> getRValueType () ;
5203
- auto rhsType = getType (rhs)-> getRValueType () ;
5203
+ auto lhsType = getType (lhs);
5204
+ auto rhsType = getType (rhs);
5204
5205
5205
5206
// If both arguments where incorrect e.g. both are function types,
5206
5207
// let's avoid producing a diagnostic second time, because first
@@ -5261,8 +5262,8 @@ bool ArgumentMismatchFailure::diagnosePatternMatchingMismatch() const {
5261
5262
auto *lhsExpr = op->getArg ()->getElement (0 );
5262
5263
auto *rhsExpr = op->getArg ()->getElement (1 );
5263
5264
5264
- auto lhsType = getType (lhsExpr)-> getRValueType () ;
5265
- auto rhsType = getType (rhsExpr)-> getRValueType () ;
5265
+ auto lhsType = getType (lhsExpr);
5266
+ auto rhsType = getType (rhsExpr);
5266
5267
5267
5268
auto diagnostic =
5268
5269
lhsType->is <UnresolvedType>()
0 commit comments