@@ -1202,32 +1202,6 @@ static Expr *getFailedArgumentExpr(CalleeCandidateInfo CCI, Expr *argExpr) {
12021202bool FailureDiagnosis::diagnoseParameterErrors (CalleeCandidateInfo &CCI,
12031203 Expr *fnExpr, Expr *argExpr,
12041204 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-
12311205 // Try to diagnose errors related to the use of implicit self reference.
12321206 if (diagnoseImplicitSelfErrors (fnExpr, argExpr, CCI, argLabels))
12331207 return true ;
@@ -1268,59 +1242,9 @@ bool FailureDiagnosis::diagnoseParameterErrors(CalleeCandidateInfo &CCI,
12681242 return false ;
12691243}
12701244
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-
13011245bool FailureDiagnosis::visitApplyExpr (ApplyExpr *callExpr) {
13021246 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 ();
13241248
13251249 bool hasTrailingClosure = callArgHasTrailingClosure (callExpr->getArg ());
13261250
@@ -1489,24 +1413,17 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) {
14891413 if (CS.getType (argExpr)->hasUnresolvedType ())
14901414 return false ;
14911415
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-
15031416 bool isInitializer = isa<TypeExpr>(fnExpr);
15041417 if (isa<TupleExpr>(argExpr) &&
15051418 cast<TupleExpr>(argExpr)->getNumElements () == 0 ) {
15061419 // Emit diagnostics that say "no arguments".
15071420 diagnose (fnExpr->getLoc (), diag::cannot_call_with_no_params,
15081421 overloadName, isInitializer);
15091422 } else {
1423+ SmallVector<AnyFunctionType::Param, 8 > params;
1424+ AnyFunctionType::decomposeInput (CS.getType (argExpr), params);
1425+ auto argString = AnyFunctionType::getParamListAsString (params);
1426+
15101427 diagnose (fnExpr->getLoc (), diag::cannot_call_with_params,
15111428 overloadName, argString, isInitializer);
15121429 }
0 commit comments