federicobond / solidity-parser-antlr

A Solidity parser for JS built on top of a robust ANTLR4 grammar
MIT License
155 stars 55 forks source link

Support inheritance specifier with optional arguments #84

Closed blitz-1306 closed 5 years ago

blitz-1306 commented 5 years ago

Brief

Solidity allows to specify arguments in the inheriance specifiers with parens. However, empty parens are also allowed (compiled tested on Remix IDE). Unfortunately, solidity-parser-antlr is failing to parse it.

It seems to be caused by the inheritanceSpecifier grammar rule which is requiring at least one argument.

Sample:

contract Base {
    uint x;

    constructor () public {
        x = x + 1;
    }
}

contract Child is Base() {
    function main() public {
        assert(x == 1); 
    }
}

Output

TypeError: Cannot read property 'length' of null
    at ASTBuilder.Expression (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:483:26)
    at ASTBuilder.visit (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1167:38)
    at ASTBuilder.<anonymous> (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1155:19)
    at Array.map (<anonymous>)
    at ASTBuilder.visit (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1154:16)
    at ASTBuilder.InheritanceSpecifier (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:118:23)
    at ASTBuilder.visit (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1167:38)
    at ASTBuilder.<anonymous> (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1155:19)
    at Array.map (<anonymous>)
    at ASTBuilder.visit (project/node_modules/solidity-parser-antlr/dist/ASTBuilder.js:1154:16)

Consider to fix. Regards.

federicobond commented 5 years ago

Thank you for the report! Version 0.4.9 is out now and should include a fix for your problem.