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

Allow distinguishing between anonymous, fallback and receive functions #10

Open
fvictorio opened this issue Feb 29, 2020 · 2 comments
Open

Comments

@fvictorio
Copy link

fvictorio commented Feb 29, 2020

Before 0.6, the so-called fallback function (which I'll call anonymous here to avoid confusion) was the only mechanism for handling calls for functions that didn't exist:

function () external payable {}

In 0.6, the anonymous function doesn't exist anymore, and it's replaced by the fallback and receive functions:

fallback() external {}
receive() external payable {}

Right now the parser doesn't seem to give information about this, so in prettier-solidity we had to do something like this: prettier-solidity/prettier-plugin-solidity#244

Not sure about the correct API here. My suggestion would be to have properties like isAnonymous, isFallbackKeyword and isReceiveKeyword (with better names).

A problem here is that the FunctionDefinition already has a lot of properties, and adding these three will probably add some redundancy too. But my suggestion is to just add them, and then do a cleanup of the API in the next major version.

@cgewecke
Copy link

cgewecke commented Mar 2, 2020

This may be separate issue, but there also seems to be problem with 0.5.x contracts that use receive as a regular function name. Reported at eth-gas-reporter #196

This:

pragma solidity ^0.5.0;

contract A {
    function receive(address from, uint256 amount) public;
}

...crashes with

/Users/cgewecke/code/koba/node_modules/solidity-parser-diligence/dist/ASTBuilder.js:127
    return this.visit(ctx.children[0]);
                                  ^

TypeError: Cannot read property '0' of null
    at ASTBuilder.ContractPart (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:127:35)
    at ASTBuilder.visit (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1304:38)
    at ASTBuilder.<anonymous> (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1292:19)
    at Array.map (<anonymous>)
    at ASTBuilder.visit (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1291:16)
    at ASTBuilder.ContractDefinition (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:113:22)
    at ASTBuilder.visit (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1304:38)
    at ASTBuilder.<anonymous> (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1292:19)
    at Array.map (<anonymous>)
    at ASTBuilder.visit (node_modules/solidity-parser-diligence/dist/ASTBuilder.js:1291:16)

@blitz-1306
Copy link

blitz-1306 commented Mar 9, 2020

Just a side-note that Solidity AST node, that is produced by SolcJS compiler, has kind property, that corresponds to used keyword, like function, receive, fallback or constructor. Since Solidity 0.7.1 there is a freeFunction value also possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants