Errors about assignment between functions of different kinds are vague and misleading
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Description
When accessing function pointers via member access some errors are misleading and some of them should not be errors.
## Environment
- Compiler version: 0.8.33
## Steps to Reproduce
```solidity
library Lib {
function libFooExternal() external {}
function libFooPublic() public {}
}
contract Base {
function baseFooExternal() external {}
}
contract C is Base {
function fooExternal() external {}
function () external fooExternalPtr = C.fooExternal; // Type function C.fooExternal() is not implicitly convertible to expected type function () external. Special functions cannot be converted to function types.
function () external libFooPublicPtr = Lib.libFooPublic; // Type function () is not implicitly convertible to expected type function () external. Special functions cannot be converted to function types.
function () external libFooExternalPtr = Lib.libFooExternal; // Type function () is not implicitly convertible to expected type function () external. Special functions cannot be converted to function types.
function () external baseFooExternalPtr = Base.baseFooExternal; // Type function Base.baseFooExternal() is not implicitly convertible to expected type function () external. Special functions cannot be converted to function types.
function f() private {
C.fooExternal(); // Cannot call function via contract type name.
Lib.libFooPublic(); // OK
Lib.libFooExternal(); // OK
Base.baseFooExternal(); // Cannot call function via contract type name.
}
}
```
Accessing functions via contract type name (`C`, `Base`) is not allowed in this case but the errors for `baseFooExternalPtr` and `fooExternalPtr` are wrong. They are generated in [isImplicitlyConvertibleTo](https://github.com/argotorg/solidity/blob/v0.8.33/libsolidity/ast/Types.cpp#L3176) which looks wrong. The proper error should not say anything about "Special functions" because it has nothing in common with them.
Moreover, initialization of `libFooPublicPtr` and `libFooExternalPtr` should be allowed, but they aren't, because the same fragment of the code disallows this.
Contributor guide
Research direction
Start in libsolidity/ast/Types.cpp at isImplicitlyConvertibleTo, then compile the Solidity reproduction from the issue with version 0.8.33 to observe the current diagnostics. Done means contract-type access reports the appropriate restriction without the misleading “Special functions” wording, while the indicated library function-pointer initializations are accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, solidity
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100