@@ -2811,7 +2811,8 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
2811
2811
auto exprType = recheckedExpr ? CS.getType (recheckedExpr) : Type ();
2812
2812
2813
2813
// If it failed and diagnosed something, then we're done.
2814
- if (!exprType) return true ;
2814
+ if (!exprType)
2815
+ return CS.TC .Diags .hadAnyError ();
2815
2816
2816
2817
// If we contextually had an inout type, and got a non-lvalue result, then
2817
2818
// we fail with a mutability error.
@@ -5274,7 +5275,7 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5274
5275
}
5275
5276
};
5276
5277
5277
- SmallVector<Type , 4 > possibleTypes;
5278
+ SmallPtrSet<TypeBase * , 4 > possibleTypes;
5278
5279
auto currentType = CS.getType (fnExpr);
5279
5280
5280
5281
// If current type has type variables or unresolved types
@@ -5294,10 +5295,10 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5294
5295
return diagnoseContextualConversionError (callExpr, contextualType,
5295
5296
CS.getContextualTypePurpose ());
5296
5297
} else {
5297
- possibleTypes.push_back (currentType);
5298
+ possibleTypes.insert (currentType. getPointer () );
5298
5299
}
5299
5300
5300
- for (auto type : possibleTypes) {
5301
+ for (Type type : possibleTypes) {
5301
5302
auto *fnType = type->getAs <AnyFunctionType>();
5302
5303
if (!fnType)
5303
5304
continue ;
@@ -5388,7 +5389,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5388
5389
auto *DC = CS.DC ;
5389
5390
5390
5391
auto typeCheckExpr = [](TypeChecker &TC, Expr *expr, DeclContext *DC,
5391
- SmallVectorImpl<Type > &types,
5392
+ SmallPtrSetImpl<TypeBase * > &types,
5392
5393
Type contextualType = Type ()) {
5393
5394
CalleeListener listener (contextualType);
5394
5395
TC.getPossibleTypesOfExpressionWithoutApplying (
@@ -5398,7 +5399,7 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5398
5399
// First let's type-check expression without contextual type, and
5399
5400
// see if that's going to produce a type, if so, let's type-check
5400
5401
// again, this time using given contextual type.
5401
- SmallVector<Type , 4 > withoutContextual;
5402
+ SmallPtrSet<TypeBase * , 4 > withoutContextual;
5402
5403
typeCheckExpr (TC, callExpr, DC, withoutContextual);
5403
5404
5404
5405
// If there are no types returned, it means that problem was
@@ -5407,12 +5408,13 @@ bool FailureDiagnosis::diagnoseCallContextualConversionErrors(
5407
5408
if (withoutContextual.empty ())
5408
5409
return false ;
5409
5410
5410
- SmallVector<Type , 4 > withContextual;
5411
+ SmallPtrSet<TypeBase * , 4 > withContextual;
5411
5412
typeCheckExpr (TC, callExpr, DC, withContextual, contextualType);
5412
5413
// If type-checking with contextual type didn't produce any results
5413
5414
// it means that we have a contextual mismatch.
5414
- if (withContextual.empty ())
5415
+ if (withContextual.empty ()) {
5415
5416
return diagnoseContextualConversionError (callExpr, contextualType, CTP);
5417
+ }
5416
5418
5417
5419
// If call produces a single type when type-checked with contextual
5418
5420
// expression, it means that the problem is elsewhere, any other
@@ -5431,15 +5433,15 @@ static bool shouldTypeCheckFunctionExpr(TypeChecker &TC, DeclContext *DC,
5431
5433
if (!isa<UnresolvedDotExpr>(fnExpr))
5432
5434
return true ;
5433
5435
5434
- SmallVector<Type , 4 > fnTypes;
5436
+ SmallPtrSet<TypeBase * , 4 > fnTypes;
5435
5437
TC.getPossibleTypesOfExpressionWithoutApplying (fnExpr, DC, fnTypes,
5436
5438
FreeTypeVariableBinding::UnresolvedType);
5437
5439
5438
5440
if (fnTypes.size () == 1 ) {
5439
5441
// Some member types depend on the arguments to produce a result type,
5440
5442
// type-checking such expressions without associated arguments is
5441
5443
// going to produce unrelated diagnostics.
5442
- if (auto fn = fnTypes[ 0 ] ->getAs <AnyFunctionType>()) {
5444
+ if (auto fn = (* fnTypes. begin ()) ->getAs <AnyFunctionType>()) {
5443
5445
auto resultType = fn->getResult ();
5444
5446
if (resultType->hasUnresolvedType () || resultType->hasTypeVariable ())
5445
5447
return false ;
@@ -5494,7 +5496,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5494
5496
isa<UnresolvedDotExpr>(callExpr->getFn ())) {
5495
5497
fnExpr = callExpr->getFn ();
5496
5498
5497
- SmallVector<Type , 4 > types;
5499
+ SmallPtrSet<TypeBase * , 4 > types;
5498
5500
CS.TC .getPossibleTypesOfExpressionWithoutApplying (fnExpr, CS.DC , types);
5499
5501
5500
5502
auto isFunctionType = [getFuncType](Type type) -> bool {
0 commit comments