diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 3fa068491d9f..cfc62b469fb3 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -457,10 +457,16 @@ MemberList::MemberMap Type::attachedFunctions(Type const& _type, ASTNode const& } } else - addFunction( - dynamic_cast(*declaration), - identifierPath->path().back() - ); + { + auto const& functionDefinition = dynamic_cast(*declaration); + // Zero-parameter functions are rejected by TypeChecker::endVisit(UsingForDirective) + // with error 4731, but member resolution can run before the directive is visited + // when the call site precedes the directive in the contract body. Skip these here + // so addFunction() does not assert in withBoundFirstArgument() (#16610). + if (functionDefinition.parameters().empty()) + continue; + addFunction(functionDefinition, identifierPath->path().back()); + } } return members; diff --git a/test/libsolidity/syntaxTests/using/using_free_no_parameters_call_site_before_directive.sol b/test/libsolidity/syntaxTests/using/using_free_no_parameters_call_site_before_directive.sol new file mode 100644 index 000000000000..eb853b75481b --- /dev/null +++ b/test/libsolidity/syntaxTests/using/using_free_no_parameters_call_site_before_directive.sol @@ -0,0 +1,11 @@ +function zero() pure returns (uint) { return 0; } + +contract C { + function f(uint z) pure external returns (uint) { + return z.zero(); + } + using {zero} for uint; +} +// ---- +// TypeError 9582: (133-139): Member "zero" not found or not visible after argument-dependent lookup in uint256. +// TypeError 4731: (160-164): The function "zero" does not have any parameters, and therefore cannot be attached to the type "uint256".