@@ -1202,32 +1202,6 @@ static Expr *getFailedArgumentExpr(CalleeCandidateInfo CCI, Expr *argExpr) {
1202
1202
bool FailureDiagnosis::diagnoseParameterErrors (CalleeCandidateInfo &CCI,
1203
1203
Expr *fnExpr, Expr *argExpr,
1204
1204
ArrayRef<Identifier> argLabels) {
1205
- if (auto *MTT = CS.getType (fnExpr)->getAs <MetatypeType>()) {
1206
- auto instTy = MTT->getInstanceType ();
1207
- auto &DE = CS.getASTContext ().Diags ;
1208
- if (instTy->getAnyNominal ()) {
1209
- // If we are invoking a constructor on a nominal type and there are
1210
- // absolutely no candidates, then they must all be private.
1211
- if (CCI.empty () || (CCI.size () == 1 && CCI.candidates [0 ].getDecl () &&
1212
- isa<ProtocolDecl>(CCI.candidates [0 ].getDecl ()))) {
1213
- DE.diagnose (fnExpr->getLoc (), diag::no_accessible_initializers,
1214
- instTy);
1215
- return true ;
1216
- }
1217
- // continue below
1218
- } else if (!instTy->is <TupleType>()) {
1219
- // If we are invoking a constructor on a non-nominal type, the expression
1220
- // is malformed.
1221
- SourceRange initExprRange (fnExpr->getSourceRange ().Start ,
1222
- argExpr->getSourceRange ().End );
1223
- DE.diagnose (fnExpr->getLoc (), instTy->isExistentialType () ?
1224
- diag::construct_protocol_by_name :
1225
- diag::non_nominal_no_initializers, instTy)
1226
- .highlight (initExprRange);
1227
- return true ;
1228
- }
1229
- }
1230
-
1231
1205
// Try to diagnose errors related to the use of implicit self reference.
1232
1206
if (diagnoseImplicitSelfErrors (fnExpr, argExpr, CCI, argLabels))
1233
1207
return true ;
@@ -1268,59 +1242,9 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
1268
1242
return false ;
1269
1243
}
1270
1244
1271
- // Check if there is a structural problem in the function expression
1272
- // by performing type checking with the option to allow unresolved
1273
- // type variables. If that is going to produce a function type with
1274
- // unresolved result let's not re-typecheck the function expression,
1275
- // because it might produce unrelated diagnostics due to lack of
1276
- // contextual information.
1277
- static bool shouldTypeCheckFunctionExpr (FailureDiagnosis &FD, DeclContext *DC,
1278
- Expr *fnExpr) {
1279
- if (!isa<UnresolvedDotExpr>(fnExpr))
1280
- return true ;
1281
-
1282
- SmallPtrSet<TypeBase *, 4 > fnTypes;
1283
- FD.getPossibleTypesOfExpressionWithoutApplying (
1284
- fnExpr, DC, fnTypes, FreeTypeVariableBinding::UnresolvedType);
1285
-
1286
- if (fnTypes.size () == 1 ) {
1287
- // Some member types depend on the arguments to produce a result type,
1288
- // type-checking such expressions without associated arguments is
1289
- // going to produce unrelated diagnostics.
1290
- if (auto fn = (*fnTypes.begin ())->getAs <AnyFunctionType>()) {
1291
- auto resultType = fn->getResult ();
1292
- if (resultType->hasUnresolvedType () || resultType->hasTypeVariable ())
1293
- return false ;
1294
- }
1295
- }
1296
-
1297
- // Might be a structural problem related to the member itself.
1298
- return true ;
1299
- }
1300
-
1301
1245
bool FailureDiagnosis::visitApplyExpr (ApplyExpr *callExpr) {
1302
1246
auto *fnExpr = callExpr->getFn ();
1303
-
1304
- if (shouldTypeCheckFunctionExpr (*this , CS.DC , fnExpr)) {
1305
- // Type check the function subexpression to resolve a type for it if
1306
- // possible.
1307
- fnExpr = typeCheckChildIndependently (callExpr->getFn ());
1308
- if (!fnExpr) {
1309
- return CS.getASTContext ().Diags .hadAnyError ();
1310
- }
1311
- }
1312
-
1313
- SWIFT_DEFER {
1314
- if (!fnExpr) return ;
1315
-
1316
- // If it's a member operator reference, put the operator back.
1317
- if (auto operatorRef = fnExpr->getMemberOperatorRef ())
1318
- callExpr->setFn (operatorRef);
1319
- };
1320
-
1321
- auto getFuncType = [](Type type) -> Type { return type->getRValueType (); };
1322
-
1323
- auto fnType = getFuncType (CS.getType (fnExpr));
1247
+ auto fnType = CS.getType (fnExpr)->getRValueType ();
1324
1248
1325
1249
bool hasTrailingClosure = callArgHasTrailingClosure (callExpr->getArg ());
1326
1250
@@ -1489,24 +1413,17 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
1489
1413
if (CS.getType (argExpr)->hasUnresolvedType ())
1490
1414
return false ;
1491
1415
1492
- SmallVector<AnyFunctionType::Param, 8 > params;
1493
- AnyFunctionType::decomposeInput (CS.getType (argExpr), params);
1494
- auto argString = AnyFunctionType::getParamListAsString (params);
1495
-
1496
- if (auto MTT = fnType->getAs <MetatypeType>()) {
1497
- if (MTT->getInstanceType ()->isExistentialType ()) {
1498
- diagnose (fnExpr->getLoc (), diag::construct_protocol_value, fnType);
1499
- return true ;
1500
- }
1501
- }
1502
-
1503
1416
bool isInitializer = isa<TypeExpr>(fnExpr);
1504
1417
if (isa<TupleExpr>(argExpr) &&
1505
1418
cast<TupleExpr>(argExpr)->getNumElements () == 0 ) {
1506
1419
// Emit diagnostics that say "no arguments".
1507
1420
diagnose (fnExpr->getLoc (), diag::cannot_call_with_no_params,
1508
1421
overloadName, isInitializer);
1509
1422
} else {
1423
+ SmallVector<AnyFunctionType::Param, 8 > params;
1424
+ AnyFunctionType::decomposeInput (CS.getType (argExpr), params);
1425
+ auto argString = AnyFunctionType::getParamListAsString (params);
1426
+
1510
1427
diagnose (fnExpr->getLoc (), diag::cannot_call_with_params,
1511
1428
overloadName, argString, isInitializer);
1512
1429
}
0 commit comments