Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to disambiguate shadowed function pointers #12296

Closed
wolflo opened this issue Nov 17, 2021 · 2 comments
Closed

Unable to disambiguate shadowed function pointers #12296

wolflo opened this issue Nov 17, 2021 · 2 comments
Labels
language design :rage4: Any changes to the language, e.g. new features

Comments

@wolflo
Copy link

wolflo commented Nov 17, 2021

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

  • Compiler version: 0.8.10

Steps to Reproduce

Pointer.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.10;

contract Pointer {
    function shadowed(uint256 a) internal {}
    function shadowed(uint256 a, uint256 b) 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);
@chriseth
Copy link
Contributor

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.

@cameel
Copy link
Member

cameel commented Jan 27, 2023

Closing as a duplicate of #3556.

@cameel cameel closed this as not planned Won't fix, can't repro, duplicate, stale Jan 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
language design :rage4: Any changes to the language, e.g. new features
Projects
None yet
Development

No branches or pull requests

4 participants