| 2423 | } |
| 2424 | |
| 2425 | void TypeChecker::typeCheckFunctionGeneralChecks( |
| 2426 | FunctionCall const& _functionCall, |
| 2427 | FunctionTypePointer _functionType |
| 2428 | ) |
| 2429 | { |
| 2430 | // Actual function call or struct constructor call. |
| 2431 | |
| 2432 | solAssert(!!_functionType, ""); |
| 2433 | solAssert(_functionType->kind() != FunctionType::Kind::ABIDecode, ""); |
| 2434 | |
| 2435 | bool const isPositionalCall = _functionCall.names().empty(); |
| 2436 | bool const isVariadic = _functionType->takesArbitraryParameters(); |
| 2437 | |
| 2438 | auto functionCallKind = *_functionCall.annotation().kind; |
| 2439 | |
| 2440 | solAssert( |
| 2441 | !isVariadic || functionCallKind == FunctionCallKind::FunctionCall, |
| 2442 | "Struct constructor calls cannot be variadic." |
| 2443 | ); |
| 2444 | |
| 2445 | TypePointers const& parameterTypes = _functionType->parameterTypes(); |
| 2446 | std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments(); |
| 2447 | std::vector<ASTPointer<ASTString>> const& argumentNames = _functionCall.names(); |
| 2448 | |
| 2449 | // Check number of passed in arguments |
| 2450 | if ( |
| 2451 | arguments.size() < parameterTypes.size() || |
| 2452 | (!isVariadic && arguments.size() > parameterTypes.size()) |
| 2453 | ) |
| 2454 | { |
| 2455 | bool const isStructConstructorCall = |
| 2456 | functionCallKind == FunctionCallKind::StructConstructorCall; |
| 2457 | |
| 2458 | auto [errorId, description] = [&]() -> std::tuple<ErrorId, std::string> { |
| 2459 | std::string msg = isVariadic ? |
| 2460 | "Need at least " + |
| 2461 | toString(parameterTypes.size()) + |
| 2462 | " arguments for " + |
| 2463 | std::string(isStructConstructorCall ? "struct constructor" : "function call") + |
| 2464 | ", but provided only " + |
| 2465 | toString(arguments.size()) + |
| 2466 | "." |
| 2467 | : |
| 2468 | "Wrong argument count for " + |
| 2469 | std::string(isStructConstructorCall ? "struct constructor" : "function call") + |
| 2470 | ": " + |
| 2471 | toString(arguments.size()) + |
| 2472 | " arguments given but " + |
| 2473 | std::string(isVariadic ? "need at least " : "expected ") + |
| 2474 | toString(parameterTypes.size()) + |
| 2475 | "."; |
| 2476 | |
| 2477 | if (isStructConstructorCall) |
| 2478 | { |
| 2479 | solAssert(!isVariadic, ""); |
| 2480 | return { 9755_error, msg }; |
| 2481 | } |
| 2482 | else if ( |
nothing calls this directly
no test coverage detected