@@ -2803,7 +2803,8 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
2803
2803
auto exprType = recheckedExpr ? CS.getType (recheckedExpr) : Type ();
2804
2804
2805
2805
// If it failed and diagnosed something, then we're done.
2806
- if (!exprType) return true ;
2806
+ if (!exprType)
2807
+ return CS.TC .Diags .hadAnyError ();
2807
2808
2808
2809
// If we contextually had an inout type, and got a non-lvalue result, then
2809
2810
// we fail with a mutability error.
@@ -5263,7 +5264,7 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5263
5264
}
5264
5265
};
5265
5266
5266
- SmallVector<Type , 4 > possibleTypes;
5267
+ SmallPtrSet<TypeBase * , 4 > possibleTypes;
5267
5268
auto currentType = CS.getType (fnExpr);
5268
5269
5269
5270
// If current type has type variables or unresolved types
@@ -5283,10 +5284,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5283
5284
return diagnoseContextualConversionError (callExpr, contextualType,
5284
5285
CS.getContextualTypePurpose ());
5285
5286
} else {
5286
- possibleTypes.push_back (currentType);
5287
+ possibleTypes.insert (currentType. getPointer () );
5287
5288
}
5288
5289
5289
- for (auto type : possibleTypes) {
5290
+ for (Type type : possibleTypes) {
5290
5291
auto *fnType = type->getAs <AnyFunctionType>();
5291
5292
if (!fnType)
5292
5293
continue ;
@@ -5377,7 +5378,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5377
5378
auto *DC = CS.DC ;
5378
5379
5379
5380
auto typeCheckExpr = [](TypeChecker &TC, Expr *expr, DeclContext *DC,
5380
- SmallVectorImpl<Type > &types,
5381
+ SmallPtrSetImpl<TypeBase * > &types,
5381
5382
Type contextualType = Type ()) {
5382
5383
CalleeListener listener (contextualType);
5383
5384
TC.getPossibleTypesOfExpressionWithoutApplying (
@@ -5387,7 +5388,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5387
5388
// First let's type-check expression without contextual type, and
5388
5389
// see if that's going to produce a type, if so, let's type-check
5389
5390
// again, this time using given contextual type.
5390
- SmallVector<Type , 4 > withoutContextual;
5391
+ SmallPtrSet<TypeBase * , 4 > withoutContextual;
5391
5392
typeCheckExpr (TC, callExpr, DC, withoutContextual);
5392
5393
5393
5394
// If there are no types returned, it means that problem was
@@ -5396,12 +5397,13 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5396
5397
if (withoutContextual.empty ())
5397
5398
return false ;
5398
5399
5399
- SmallVector<Type , 4 > withContextual;
5400
+ SmallPtrSet<TypeBase * , 4 > withContextual;
5400
5401
typeCheckExpr (TC, callExpr, DC, withContextual, contextualType);
5401
5402
// If type-checking with contextual type didn't produce any results
5402
5403
// it means that we have a contextual mismatch.
5403
- if (withContextual.empty ())
5404
+ if (withContextual.empty ()) {
5404
5405
return diagnoseContextualConversionError (callExpr, contextualType, CTP);
5406
+ }
5405
5407
5406
5408
// If call produces a single type when type-checked with contextual
5407
5409
// expression, it means that the problem is elsewhere, any other
@@ -5420,15 +5422,15 @@ static bool shouldTypeCheckFunctionExpr(TypeChecker &TC, DeclContext *DC,
5420
5422
if (!isa<UnresolvedDotExpr>(fnExpr))
5421
5423
return true ;
5422
5424
5423
- SmallVector<Type , 4 > fnTypes;
5425
+ SmallPtrSet<TypeBase * , 4 > fnTypes;
5424
5426
TC.getPossibleTypesOfExpressionWithoutApplying (fnExpr, DC, fnTypes,
5425
5427
FreeTypeVariableBinding::UnresolvedType);
5426
5428
5427
5429
if (fnTypes.size () == 1 ) {
5428
5430
// Some member types depend on the arguments to produce a result type,
5429
5431
// type-checking such expressions without associated arguments is
5430
5432
// going to produce unrelated diagnostics.
5431
- if (auto fn = fnTypes[ 0 ] ->getAs <AnyFunctionType>()) {
5433
+ if (auto fn = (* fnTypes. begin ()) ->getAs <AnyFunctionType>()) {
5432
5434
auto resultType = fn->getResult ();
5433
5435
if (resultType->hasUnresolvedType () || resultType->hasTypeVariable ())
5434
5436
return false ;
@@ -5483,7 +5485,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5483
5485
isa<UnresolvedDotExpr>(callExpr->getFn ())) {
5484
5486
fnExpr = callExpr->getFn ();
5485
5487
5486
- SmallVector<Type , 4 > types;
5488
+ SmallPtrSet<TypeBase * , 4 > types;
5487
5489
CS.TC .getPossibleTypesOfExpressionWithoutApplying (fnExpr, CS.DC , types);
5488
5490
5489
5491
auto isFunctionType = [getFuncType](Type type) -> bool {
0 commit comments