@@ -1805,8 +1805,8 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){
1805
1805
if (!srcFT->isNoEscape ()) destExtInfo = destExtInfo.withNoEscape (false );
1806
1806
if (!srcFT->throws ()) destExtInfo = destExtInfo.withThrows (false );
1807
1807
if (destExtInfo != destFT->getExtInfo ())
1808
- toType = FunctionType::get (destFT->getInput (),
1809
- destFT-> getResult (), destExtInfo);
1808
+ toType = FunctionType::get (destFT->getParams (), destFT-> getResult (),
1809
+ destExtInfo);
1810
1810
1811
1811
// If this is a function conversion that discards throwability or
1812
1812
// noescape, emit a specific diagnostic about that.
@@ -2978,7 +2978,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
2978
2978
// If we're trying to convert something of type "() -> T" to T, then we
2979
2979
// probably meant to call the value.
2980
2980
if (auto srcFT = exprType->getAs <AnyFunctionType>()) {
2981
- if (srcFT->getInput ()-> isVoid () &&
2981
+ if (srcFT->getParams (). empty () &&
2982
2982
!isUnresolvedOrTypeVarType (srcFT->getResult ()) &&
2983
2983
CS.TC .isConvertibleTo (srcFT->getResult (), contextualType, CS.DC )) {
2984
2984
diagnose (expr->getLoc (), diag::missing_nullary_call, srcFT->getResult ())
@@ -3071,7 +3071,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError(
3071
3071
if (!srcFT->isNoEscape ()) destExtInfo = destExtInfo.withNoEscape (false );
3072
3072
if (!srcFT->throws ()) destExtInfo = destExtInfo.withThrows (false );
3073
3073
if (destExtInfo != destFT->getExtInfo ())
3074
- contextualType = FunctionType::get (destFT->getInput (),
3074
+ contextualType = FunctionType::get (destFT->getParams (),
3075
3075
destFT->getResult (), destExtInfo);
3076
3076
3077
3077
// If this is a function conversion that discards throwability or
@@ -3896,7 +3896,8 @@ diagnoseInstanceMethodAsCurriedMemberOnType(CalleeCandidateInfo &CCI,
3896
3896
}
3897
3897
3898
3898
static bool diagnoseTupleParameterMismatch (CalleeCandidateInfo &CCI,
3899
- Type paramType, Type argType,
3899
+ ArrayRef<AnyFunctionType::Param> params,
3900
+ ArrayRef<AnyFunctionType::Param> args,
3900
3901
Expr *fnExpr, Expr *argExpr,
3901
3902
bool isTopLevel = true ) {
3902
3903
// Try to diagnose function call tuple parameter splat only if
@@ -3913,72 +3914,96 @@ static bool diagnoseTupleParameterMismatch(CalleeCandidateInfo &CCI,
3913
3914
}
3914
3915
}
3915
3916
3916
- if (auto *paramFnType = paramType->getAs <AnyFunctionType>()) {
3917
- // Only if both of the parameter and argument types are functions
3918
- // let's recur into diagnosing their arguments.
3919
- if (auto *argFnType = argType->getAs <AnyFunctionType>())
3920
- return diagnoseTupleParameterMismatch (CCI, paramFnType->getInput (),
3921
- argFnType->getInput (), fnExpr,
3922
- argExpr, /* isTopLevel */ false );
3923
- return false ;
3917
+ if (params.size () == 1 && args.size () == 1 ) {
3918
+ auto paramType = params.front ().getType ();
3919
+ auto argType = args.front ().getType ();
3920
+
3921
+ if (auto *paramFnType = paramType->getAs <AnyFunctionType>()) {
3922
+ // Only if both of the parameter and argument types are functions
3923
+ // let's recur into diagnosing their arguments.
3924
+ if (auto *argFnType = argType->getAs <AnyFunctionType>())
3925
+ return diagnoseTupleParameterMismatch (CCI, paramFnType->getParams (),
3926
+ argFnType->getParams (), fnExpr,
3927
+ argExpr, /* isTopLevel */ false );
3928
+ return false ;
3929
+ }
3924
3930
}
3925
3931
3926
- unsigned parameterCount = 1 , argumentCount = 1 ;
3932
+ if (params.size () != 1 || args.empty ())
3933
+ return false ;
3927
3934
3928
- // Don't try to desugar ParenType which is going to result in incorrect
3929
- // inferred argument/parameter count.
3935
+ auto paramType = params.front ().getType ();
3930
3936
3931
- if (auto *paramTypeTy = dyn_cast<TupleType>(paramType.getPointer ()))
3932
- parameterCount = paramTypeTy->getNumElements ();
3937
+ if (args.size () == 1 ) {
3938
+ auto argType = args.front ().getType ();
3939
+ if (auto *paramFnType = paramType->getAs <AnyFunctionType>()) {
3940
+ // Only if both of the parameter and argument types are functions
3941
+ // let's recur into diagnosing their arguments.
3942
+ if (auto *argFnType = argType->getAs <AnyFunctionType>())
3943
+ return diagnoseTupleParameterMismatch (CCI, paramFnType->getParams (),
3944
+ argFnType->getParams (), fnExpr,
3945
+ argExpr, /* isTopLevel */ false );
3946
+ }
3933
3947
3934
- if ( auto *argTupleTy = dyn_cast<TupleType>(argType. getPointer ()))
3935
- argumentCount = argTupleTy-> getNumElements ();
3948
+ return false ;
3949
+ }
3936
3950
3937
- if (parameterCount == 1 && argumentCount > 1 ) {
3938
- // Let's see if inferred argument is actually a tuple inside of Paren.
3939
- auto *paramTupleTy = paramType->getAs <TupleType>();
3940
- if (!paramTupleTy)
3941
- return false ;
3951
+ // Let's see if inferred argument is actually a tuple inside of Paren.
3952
+ auto *paramTupleTy = paramType->getAs <TupleType>();
3953
+ if (!paramTupleTy)
3954
+ return false ;
3942
3955
3943
- // Looks like the number of tuple elements matches number
3944
- // of function arguments, which means we can we can emit an
3945
- // error about an attempt to make use of tuple splat or tuple
3946
- // destructuring, unfortunately we can't provide a fix-it for
3947
- // this case.
3948
- if (paramTupleTy->getNumElements () == argumentCount) {
3949
- auto &TC = CCI.CS .TC ;
3950
- if (isTopLevel) {
3951
- if (auto *decl = CCI[0 ].getDecl ()) {
3952
- Identifier name;
3953
- auto kind = decl->getDescriptiveKind ();
3954
- // Constructors/descructors and subscripts don't really have names.
3955
- if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
3956
- isa<SubscriptDecl>(decl))) {
3957
- name = decl->getBaseName ().getIdentifier ();
3958
- }
3956
+ if (paramTupleTy->getNumElements () != args.size ())
3957
+ return false ;
3959
3958
3960
- TC.diagnose (argExpr->getLoc (), diag::single_tuple_parameter_mismatch,
3961
- kind, name, paramType, !name.empty ())
3962
- .highlight (argExpr->getSourceRange ())
3963
- .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3964
- .fixItInsert (argExpr->getEndLoc (), " )" );
3965
- } else {
3966
- TC.diagnose (argExpr->getLoc (),
3967
- diag::unknown_single_tuple_parameter_mismatch, paramType)
3968
- .highlight (argExpr->getSourceRange ())
3969
- .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3970
- .fixItInsert (argExpr->getEndLoc (), " )" );
3971
- }
3972
- } else {
3973
- TC.diagnose (argExpr->getLoc (),
3974
- diag::nested_tuple_parameter_destructuring, paramType,
3975
- CCI.CS .getType (fnExpr));
3959
+ // Looks like the number of tuple elements matches number
3960
+ // of function arguments, which means we can we can emit an
3961
+ // error about an attempt to make use of tuple splat or tuple
3962
+ // destructuring, unfortunately we can't provide a fix-it for
3963
+ // this case.
3964
+ auto &TC = CCI.CS .TC ;
3965
+ if (isTopLevel) {
3966
+ if (auto *decl = CCI[0 ].getDecl ()) {
3967
+ Identifier name;
3968
+ auto kind = decl->getDescriptiveKind ();
3969
+ // Constructors/descructors and subscripts don't really have names.
3970
+ if (!(isa<ConstructorDecl>(decl) || isa<DestructorDecl>(decl) ||
3971
+ isa<SubscriptDecl>(decl))) {
3972
+ name = decl->getBaseName ().getIdentifier ();
3976
3973
}
3977
- return true ;
3974
+
3975
+ TC.diagnose (argExpr->getLoc (), diag::single_tuple_parameter_mismatch,
3976
+ kind, name, paramTupleTy, !name.empty ())
3977
+ .highlight (argExpr->getSourceRange ())
3978
+ .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3979
+ .fixItInsert (argExpr->getEndLoc (), " )" );
3980
+ } else {
3981
+ TC.diagnose (argExpr->getLoc (),
3982
+ diag::unknown_single_tuple_parameter_mismatch, paramTupleTy)
3983
+ .highlight (argExpr->getSourceRange ())
3984
+ .fixItInsertAfter (argExpr->getStartLoc (), " (" )
3985
+ .fixItInsert (argExpr->getEndLoc (), " )" );
3978
3986
}
3987
+ } else {
3988
+ TC.diagnose (argExpr->getLoc (),
3989
+ diag::nested_tuple_parameter_destructuring, paramTupleTy,
3990
+ CCI.CS .getType (fnExpr));
3979
3991
}
3980
3992
3981
- return false ;
3993
+ return true ;
3994
+ }
3995
+
3996
+ static bool diagnoseTupleParameterMismatch (CalleeCandidateInfo &CCI,
3997
+ Type paramType, Type argType,
3998
+ Expr *fnExpr, Expr *argExpr,
3999
+ bool isTopLevel = true ) {
4000
+ llvm::SmallVector<AnyFunctionType::Param, 4 > params, args;
4001
+
4002
+ FunctionType::decomposeInput (paramType, params);
4003
+ FunctionType::decomposeInput (argType, args);
4004
+
4005
+ return diagnoseTupleParameterMismatch (CCI, params, args, fnExpr, argExpr,
4006
+ isTopLevel);
3982
4007
}
3983
4008
3984
4009
class ArgumentMatcher : public MatchCallArgumentListener {
@@ -4650,7 +4675,9 @@ bool FailureDiagnosis::diagnoseSubscriptErrors(SubscriptExpr *SE,
4650
4675
auto candType = baseType->getTypeOfMember (CS.DC ->getParentModule (),
4651
4676
cand.getDecl (), nullptr );
4652
4677
if (auto *candFunc = candType->getAs <FunctionType>()) {
4653
- auto paramsType = candFunc->getInput ();
4678
+ auto paramsType = FunctionType::composeInput (CS.getASTContext (),
4679
+ candFunc->getParams (),
4680
+ false );
4654
4681
if (!typeCheckChildIndependently (
4655
4682
indexExpr, paramsType, CTP_CallArgument, TCC_ForceRecheck))
4656
4683
return true ;
@@ -5227,25 +5254,11 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5227
5254
if (!fnType)
5228
5255
continue ;
5229
5256
5230
- auto paramType = fnType->getInput ();
5231
- switch (paramType->getKind ()) {
5232
- case TypeKind::Tuple: {
5233
- auto tuple = paramType->getAs <TupleType>();
5234
- if (tuple->getNumElements () != 1 )
5235
- continue ;
5236
-
5237
- paramType = tuple->getElement (0 ).getType ();
5238
- break ;
5239
- }
5240
-
5241
- case TypeKind::Paren:
5242
- paramType = paramType->getWithoutParens ();
5243
- break ;
5244
-
5245
- default :
5257
+ auto params = fnType->getParams ();
5258
+ if (params.size () != 1 )
5246
5259
return false ;
5247
- }
5248
5260
5261
+ Type paramType = params.front ().getType ();
5249
5262
if (auto paramFnType = paramType->getAs <AnyFunctionType>()) {
5250
5263
auto closureType = CS.getType (closureExpr);
5251
5264
if (auto *argFnType = closureType->getAs <AnyFunctionType>()) {
@@ -5298,7 +5311,7 @@ bool FailureDiagnosis::diagnoseTrailingClosureErrors(ApplyExpr *callExpr) {
5298
5311
}
5299
5312
};
5300
5313
5301
- auto expectedArgType = FunctionType::get (fnType->getInput (), resultType,
5314
+ auto expectedArgType = FunctionType::get (fnType->getParams (), resultType,
5302
5315
fnType->getExtInfo ());
5303
5316
5304
5317
llvm::SaveAndRestore<DeclContext *> SavedDC (CS.DC , DC);
@@ -5582,10 +5595,11 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
5582
5595
calleeInfo))
5583
5596
return true ;
5584
5597
5585
- Type argType; // Type of the argument list, if knowable.
5586
- if (auto FTy = fnType->getAs <AnyFunctionType>())
5587
- argType = FTy->getInput ();
5588
- else if (auto MTT = fnType->getAs <AnyMetatypeType>()) {
5598
+ Type argType; // argument list, if known.
5599
+ if (auto FTy = fnType->getAs <AnyFunctionType>()) {
5600
+ argType = FunctionType::composeInput (CS.getASTContext (), FTy->getParams (),
5601
+ false );
5602
+ } else if (auto MTT = fnType->getAs <AnyMetatypeType>()) {
5589
5603
// If we are constructing a tuple with initializer syntax, the expected
5590
5604
// argument list is the tuple type itself - and there is no initdecl.
5591
5605
auto instanceTy = MTT->getInstanceType ();
@@ -6242,7 +6256,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
6242
6256
if (contextualType && contextualType->is <AnyFunctionType>()) {
6243
6257
auto fnType = contextualType->getAs <AnyFunctionType>();
6244
6258
auto *params = CE->getParameters ();
6245
- Type inferredArgType = fnType->getInput ();
6259
+ auto inferredArgs = fnType->getParams ();
6246
6260
6247
6261
// It is very common for a contextual type to disagree with the argument
6248
6262
// list built into the closure expr. This can be because the closure expr
@@ -6252,11 +6266,7 @@ bool FailureDiagnosis::diagnoseClosureExpr(
6252
6266
// { $0 + $1 }
6253
6267
// in either case, we want to produce nice and clear diagnostics.
6254
6268
unsigned actualArgCount = params->size ();
6255
- unsigned inferredArgCount = 1 ;
6256
- // Don't try to desugar ParenType which is going to result in incorrect
6257
- // inferred argument count.
6258
- if (auto *argTupleTy = dyn_cast<TupleType>(inferredArgType.getPointer ()))
6259
- inferredArgCount = argTupleTy->getNumElements ();
6269
+ unsigned inferredArgCount = inferredArgs.size ();
6260
6270
6261
6271
if (actualArgCount != inferredArgCount) {
6262
6272
// If the closure didn't specify any arguments and it is in a context that
@@ -6288,8 +6298,9 @@ bool FailureDiagnosis::diagnoseClosureExpr(
6288
6298
}
6289
6299
6290
6300
if (inferredArgCount == 1 && actualArgCount > 1 ) {
6301
+ auto *argTupleTy = inferredArgs.front ().getType ()->getAs <TupleType>();
6291
6302
// Let's see if inferred argument is actually a tuple inside of Paren.
6292
- if (auto * argTupleTy = inferredArgType-> getAs <TupleType>() ) {
6303
+ if (argTupleTy) {
6293
6304
// Looks like the number of closure parameters matches number
6294
6305
// of inferred arguments, which means we can we can emit an
6295
6306
// error about an attempt to make use of tuple splat or tuple
@@ -6310,9 +6321,6 @@ bool FailureDiagnosis::diagnoseClosureExpr(
6310
6321
auto diag = diagnose (params->getStartLoc (),
6311
6322
diag::closure_tuple_parameter_destructuring,
6312
6323
argTupleTy);
6313
- Type actualArgType;
6314
- if (auto *actualFnType = CS.getType (CE)->getAs <AnyFunctionType>())
6315
- actualArgType = actualFnType->getInput ();
6316
6324
6317
6325
auto *closureBody = CE->getBody ();
6318
6326
if (!closureBody)
@@ -6432,7 +6440,8 @@ bool FailureDiagnosis::diagnoseClosureExpr(
6432
6440
// Okay, the wrong number of arguments was used, complain about that.
6433
6441
// Before doing so, strip attributes off the function type so that they
6434
6442
// don't confuse the issue.
6435
- fnType = FunctionType::get (fnType->getInput (), fnType->getResult ());
6443
+ fnType = FunctionType::get (fnType->getParams (), fnType->getResult (),
6444
+ fnType->getExtInfo (), false );
6436
6445
auto diag = diagnose (
6437
6446
params->getStartLoc (), diag::closure_argument_list_tuple, fnType,
6438
6447
inferredArgCount, actualArgCount, (actualArgCount == 1 ));
@@ -7490,7 +7499,7 @@ bool FailureDiagnosis::diagnoseMemberFailures(
7490
7499
// call the function, e.g. in "a.b.c" where they had to write "a.b().c".
7491
7500
// Produce a specific diagnostic + fixit for this situation.
7492
7501
if (auto baseFTy = baseObjTy->getAs <AnyFunctionType>()) {
7493
- if (baseExpr && baseFTy->getInput ()-> isVoid ()) {
7502
+ if (baseExpr && baseFTy->getParams (). empty ()) {
7494
7503
SourceLoc insertLoc = baseExpr->getEndLoc ();
7495
7504
7496
7505
if (auto *DRE = dyn_cast<DeclRefExpr>(baseExpr)) {
0 commit comments