MCPcopy Create free account
hub / github.com/argotorg/solidity / typeCheckABIEncodeCallFunction

Method typeCheckABIEncodeCallFunction

libsolidity/analysis/TypeChecker.cpp:2186–2337  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2184}
2185
2186void TypeChecker::typeCheckABIEncodeCallFunction(FunctionCall const& _functionCall)
2187{
2188 std::vector<ASTPointer<Expression const>> const& arguments = _functionCall.arguments();
2189
2190 // Expecting first argument to be the function pointer and second to be a tuple.
2191 if (arguments.size() != 2)
2192 {
2193 m_errorReporter.typeError(
2194 6219_error,
2195 _functionCall.location(),
2196 "Expected two arguments: a function pointer followed by a tuple."
2197 );
2198 return;
2199 }
2200
2201 FunctionType const* externalFunctionType = nullptr;
2202 if (auto const functionPointerType = dynamic_cast<FunctionTypePointer>(type(*arguments.front())))
2203 {
2204 // this cannot be a library function, that is checked below
2205 externalFunctionType = functionPointerType->asExternallyCallableFunction(false);
2206 solAssert(externalFunctionType->kind() == functionPointerType->kind());
2207 }
2208 else
2209 {
2210 m_errorReporter.typeError(
2211 5511_error,
2212 arguments.front()->location(),
2213 "Expected first argument to be a function pointer, not \"" +
2214 type(*arguments.front())->humanReadableName() +
2215 "\"."
2216 );
2217 return;
2218 }
2219
2220 if (
2221 externalFunctionType->kind() != FunctionType::Kind::External &&
2222 externalFunctionType->kind() != FunctionType::Kind::Declaration
2223 )
2224 {
2225 std::string msg = "Expected regular external function type, or external view on public function.";
2226
2227 switch (externalFunctionType->kind())
2228 {
2229 case FunctionType::Kind::Internal:
2230 msg += " Provided internal function.";
2231 break;
2232 case FunctionType::Kind::DelegateCall:
2233 msg += " Cannot use library functions for abi.encodeCall.";
2234 break;
2235 case FunctionType::Kind::Creation:
2236 msg += " Provided creation function.";
2237 break;
2238 case FunctionType::Kind::Event:
2239 msg += " Cannot use events for abi.encodeCall.";
2240 break;
2241 case FunctionType::Kind::Error:
2242 msg += " Cannot use errors for abi.encodeCall.";
2243 break;

Callers

nothing calls this directly

Calls 15

typeFunction · 0.85
containsFunction · 0.85
typeErrorMethod · 0.80
hasDeclarationMethod · 0.80
declarationMethod · 0.80
scopeMethod · 0.80
parameterTypesMethod · 0.80
to_stringFunction · 0.50
argumentsMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected