solc-typed-ast
solc-typed-ast copied to clipboard
Function types are broken
When we try to infer types on the following sample:
pragma solidity 0.8.29;
library Lib {
function callAndAddOne(function () internal returns (uint) a) internal returns (uint) {
return a() + 1;
}
}
contract Foo {
using { Lib.callAndAddOne } for function () internal returns (uint);
function getOne() public returns (uint) {
return 1;
}
function main() public {
assert(getOne.callAndAddOne() == 2);
}
}
We fail to type getOne.callAndAddOne. The issue is in InferType.typeOfMemberAccessUsingFor here:
const usingForTyp = this.typeNameToTypeNode(usingFor.vTypeName);
match = eq(usingForTyp, generalizeType(baseT)[0]);
The type name in the using for clause is "function () returns (uint256)" while the type of getOne is "function getOne() public returns (uint256)"
There are 2 problems causing an issue here:
- One of the types has a name in it
- The visibilities differ
So:
- Function names are irrelevant to the function type and should not be there
- We should investigate limiting the solc types to Internal and External so they match the formal type defs. This requires inferring from tree context whether a function name is meant internally or externally.