You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Attempting to pass a function pointer where the name of the function being passed is shadowed results in Error: No matching declaration found after variable lookup.
In theory, the compiler should be able to disambiguate which version of the function is being passed based on the type definition where the function pointer is used.
Environment
Compiler version: 0.8.10
Steps to Reproduce
Pointer.sol
// SPDX-License-Identifier: MITpragma solidity0.8.10;
contractPointer {
function shadowed(uint256a) internal {}
function shadowed(uint256a, uint256b) internal {}
function passFn() internal {
takeFn(shadowed);
}
function takeFn(function(uint256) internal fnPtr) private {
fnPtr(0);
}
}
$ solc --version
Version: 0.8.10+commit.fc410830.Linux.g++
$ solc Pointer.sol
Error: No matching declaration found after variable lookup.
--> Pointer.sol:8:16:
|
8 | takeFn(shadowed);| ^^^^^^^^
Removing the shadowing function (shadowed(uint256, uint256)) results in a compile-able contract.
Because takeFn() explicitly accepts a function pointer of type shadowed(uint256), it should be possible to determine which version of the method is being passed.
In cases where this isn't possible, it could be nice to have some syntax at the callsite to differentiate which version of a function is expected, though this may be a significant syntactic change. To steal from rust's turbofish operator as an example:
fnPtr::<&shadowed(uint256)>(100);
The text was updated successfully, but these errors were encountered:
Solidity only performs overload resolution when a function is called, and not later during type checks. We are thinking about allowing explicit disambiguation, but this is currently not on our roadmap, also because we think that this problem does not occur often.
Description
Attempting to pass a function pointer where the name of the function being passed is shadowed results in
Error: No matching declaration found after variable lookup
.In theory, the compiler should be able to disambiguate which version of the function is being passed based on the type definition where the function pointer is used.
Environment
Steps to Reproduce
Pointer.sol
Removing the shadowing function (
shadowed(uint256, uint256)
) results in a compile-able contract.Because
takeFn()
explicitly accepts a function pointer of typeshadowed(uint256)
, it should be possible to determine which version of the method is being passed.In cases where this isn't possible, it could be nice to have some syntax at the callsite to differentiate which version of a function is expected, though this may be a significant syntactic change. To steal from rust's turbofish operator as an example:
The text was updated successfully, but these errors were encountered: