@@ -893,8 +893,7 @@ class FailureDiagnosis :public ASTVisitor<FailureDiagnosis, /*exprresult*/bool>{
893
893
// / Attempt to produce a diagnostic for a mismatch between an expression's
894
894
// / type and its assumed contextual type.
895
895
bool diagnoseContextualConversionError (Expr *expr, Type contextualType,
896
- ContextualTypePurpose CTP,
897
- Type suggestedType = Type());
896
+ ContextualTypePurpose CTP);
898
897
899
898
// / For an expression being type checked with a CTP_CalleeResult contextual
900
899
// / type, try to diagnose a problem.
@@ -2789,8 +2788,7 @@ static bool tryDiagnoseNonEscapingParameterToEscaping(
2789
2788
}
2790
2789
2791
2790
bool FailureDiagnosis::diagnoseContextualConversionError (
2792
- Expr *expr, Type contextualType, ContextualTypePurpose CTP,
2793
- Type suggestedType) {
2791
+ Expr *expr, Type contextualType, ContextualTypePurpose CTP) {
2794
2792
// If the constraint system has a contextual type, then we can test to see if
2795
2793
// this is the problem that prevents us from solving the system.
2796
2794
if (!contextualType) {
@@ -2809,16 +2807,11 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
2809
2807
if (contextualType->is <InOutType>())
2810
2808
options |= TCC_AllowLValue;
2811
2809
2812
- auto * recheckedExpr = typeCheckChildIndependently (expr, options);
2810
+ auto recheckedExpr = typeCheckChildIndependently (expr, options);
2813
2811
auto exprType = recheckedExpr ? CS.getType (recheckedExpr) : Type ();
2814
2812
2815
- // If there is a suggested type and re-typecheck failed, let's use it.
2816
- if (!exprType)
2817
- exprType = suggestedType;
2818
-
2819
2813
// If it failed and diagnosed something, then we're done.
2820
- if (!exprType)
2821
- return CS.TC .Diags .hadAnyError ();
2814
+ if (!exprType) return true ;
2822
2815
2823
2816
// If we contextually had an inout type, and got a non-lvalue result, then
2824
2817
// we fail with a mutability error.
@@ -5281,7 +5274,7 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5281
5274
}
5282
5275
};
5283
5276
5284
- SmallPtrSet<TypeBase * , 4 > possibleTypes;
5277
+ SmallVector<Type , 4 > possibleTypes;
5285
5278
auto currentType = CS.getType (fnExpr);
5286
5279
5287
5280
// If current type has type variables or unresolved types
@@ -5301,10 +5294,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5301
5294
return diagnoseContextualConversionError (callExpr, contextualType,
5302
5295
CS.getContextualTypePurpose ());
5303
5296
} else {
5304
- possibleTypes.insert (currentType. getPointer () );
5297
+ possibleTypes.push_back (currentType);
5305
5298
}
5306
5299
5307
- for (Type type : possibleTypes) {
5300
+ for (auto type : possibleTypes) {
5308
5301
auto *fnType = type->getAs <AnyFunctionType>();
5309
5302
if (!fnType)
5310
5303
continue ;
@@ -5395,7 +5388,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5395
5388
auto *DC = CS.DC ;
5396
5389
5397
5390
auto typeCheckExpr = [](TypeChecker &TC, Expr *expr, DeclContext *DC,
5398
- SmallPtrSetImpl<TypeBase * > &types,
5391
+ SmallVectorImpl<Type > &types,
5399
5392
Type contextualType = Type ()) {
5400
5393
CalleeListener listener (contextualType);
5401
5394
TC.getPossibleTypesOfExpressionWithoutApplying (
@@ -5405,7 +5398,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5405
5398
// First let's type-check expression without contextual type, and
5406
5399
// see if that's going to produce a type, if so, let's type-check
5407
5400
// again, this time using given contextual type.
5408
- SmallPtrSet<TypeBase * , 4 > withoutContextual;
5401
+ SmallVector<Type , 4 > withoutContextual;
5409
5402
typeCheckExpr (TC, callExpr, DC, withoutContextual);
5410
5403
5411
5404
// If there are no types returned, it means that problem was
@@ -5414,17 +5407,12 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5414
5407
if (withoutContextual.empty ())
5415
5408
return false ;
5416
5409
5417
- SmallPtrSet<TypeBase * , 4 > withContextual;
5410
+ SmallVector<Type , 4 > withContextual;
5418
5411
typeCheckExpr (TC, callExpr, DC, withContextual, contextualType);
5419
5412
// If type-checking with contextual type didn't produce any results
5420
5413
// it means that we have a contextual mismatch.
5421
- if (withContextual.empty ()) {
5422
- // If there is just a single choice, we can hit contextual diagnostics
5423
- // about it in case re-typecheck fails.
5424
- Type exprType = withoutContextual.size () == 1 ? *withoutContextual.begin () : Type ();
5425
- return diagnoseContextualConversionError (callExpr, contextualType, CTP,
5426
- exprType);
5427
- }
5414
+ if (withContextual.empty ())
5415
+ return diagnoseContextualConversionError (callExpr, contextualType, CTP);
5428
5416
5429
5417
// If call produces a single type when type-checked with contextual
5430
5418
// expression, it means that the problem is elsewhere, any other
@@ -5443,15 +5431,15 @@ static bool shouldTypeCheckFunctionExpr(TypeChecker &TC, DeclContext *DC,
5443
5431
if (!isa<UnresolvedDotExpr>(fnExpr))
5444
5432
return true ;
5445
5433
5446
- SmallPtrSet<TypeBase * , 4 > fnTypes;
5434
+ SmallVector<Type , 4 > fnTypes;
5447
5435
TC.getPossibleTypesOfExpressionWithoutApplying (fnExpr, DC, fnTypes,
5448
5436
FreeTypeVariableBinding::UnresolvedType);
5449
5437
5450
5438
if (fnTypes.size () == 1 ) {
5451
5439
// Some member types depend on the arguments to produce a result type,
5452
5440
// type-checking such expressions without associated arguments is
5453
5441
// going to produce unrelated diagnostics.
5454
- if (auto fn = (* fnTypes. begin ()) ->getAs <AnyFunctionType>()) {
5442
+ if (auto fn = fnTypes[ 0 ] ->getAs <AnyFunctionType>()) {
5455
5443
auto resultType = fn->getResult ();
5456
5444
if (resultType->hasUnresolvedType () || resultType->hasTypeVariable ())
5457
5445
return false ;
@@ -5506,7 +5494,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5506
5494
isa<UnresolvedDotExpr>(callExpr->getFn ())) {
5507
5495
fnExpr = callExpr->getFn ();
5508
5496
5509
- SmallPtrSet<TypeBase * , 4 > types;
5497
+ SmallVector<Type , 4 > types;
5510
5498
CS.TC .getPossibleTypesOfExpressionWithoutApplying (fnExpr, CS.DC , types);
5511
5499
5512
5500
auto isFunctionType = [getFuncType](Type type) -> bool {
0 commit comments