solhint icon indicating copy to clipboard operation
solhint copied to clipboard

address property of function types is not supported

Open ecp4224 opened this issue 2 years ago • 0 comments

When using properties of a function type variable, the address property isn't recognized

Example

pragma solidity ^0.8.0;

contract ATest {
    struct SavedCallbackFunction {
        function (uint256) external returns (bool) func;
    }

    mapping(bytes32 => SavedCallbackFunction[]) private listeners;

    function on(bytes32 eventId, function (uint256) external returns (bool) callback) external {
        listeners[eventId].push(SavedCallbackFunction(callback));
    }

    function _trigger(bytes32 eventId, uint256 data) internal {
        SavedCallbackFunction[] storage callbacks = listeners[eventId];

        for (uint i = 0; i < callbacks.length; i++) {
            bytes4 listenerFuncSelector = callbacks[i].func.selector;
            address listenerAddress = callbacks[i].func.address; //This line errors in solhint

            bytes memory cdata = abi.encodeWithSelector(listenerFuncSelector, data);

            (bool success, bytes memory result) = listenerAddress.delegatecall{gas: gasleft()}(cdata);

            require(success, string(result));
        }
    }
}

Error

error  Parse error: missing {'from', 'error', 'calldata', 'revert', 'callback', 'leave', 'payable', 'constructor', 'receive', Identifier} at 'address'

solc can compile this sample fine with no errors.

Tested on 3.3.7

This may be related to this open issue in solidity-parser/antlr

ecp4224 avatar May 04 '22 17:05 ecp4224