solidity-parser / parser

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

Bug: Expanded fallback function syntax not properly parsed #65

Closed Oighty closed 2 years ago

Oighty commented 2 years ago

Fallback functions with the expanded syntax for inputs and output: fallback (bytes calldata input) external [payable] returns (bytes memory output) are not correctly parsed. This syntax is valid per the latest Solidity documentation.

This issue is in reference to a related bug in the prettier-solidity/prettier-plugin-solidity repo (issue 659) where fallback functions with parameters and returnParameters are not correctly formatted.

I believe the issue is that the parser doesn't capture the parameters and returnsParameters when the fallback keyword is identified in parser/ASTBuilder.ts https://github.com/solidity-parser/parser/blob/1a7bfb8752821945f894d47cbe588d1b0478541d/src/ASTBuilder.ts#L342-L345

A potential fix is using the parameter and returnParameter parsing logic implemented for the function keyword starting on line 354 of the same file:

parameters = ctx
  .parameterList()
  .parameter()
  .map((x) => this.visit(x))
returnParameters =
  ctxReturnParameters !== undefined
    ? this.visitReturnParameters(ctxReturnParameters)
    : null
mnusurov commented 2 years ago

Having the same issue would appreciate it if this can be fixed asap.

Janther commented 2 years ago

The same applies to receive functions