solc-typed-ast icon indicating copy to clipboard operation
solc-typed-ast copied to clipboard

Function types are broken

Open d1m0 opened this issue 2 weeks ago • 0 comments

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:

  1. One of the types has a name in it
  2. The visibilities differ

So:

  1. Function names are irrelevant to the function type and should not be there
  2. 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.

d1m0 avatar Nov 17 '25 14:11 d1m0