unpackdev / solgo

Solidity parser in Go, designed to transform Solidity code into a structured format for enhanced analysis, particularly beneficial for developers using Go to analyze Solidity smart contracts.
https://unpack.dev
Apache License 2.0
1 stars 0 forks source link

[Bug] Parsing of params for AST function declaration #198

Closed xianlinc closed 5 months ago

xianlinc commented 5 months ago

Problem

Parsing a function without arguments, for example increment() returns (uint256), we are not getting the correct arguments in the resulting function declaration node.

Expected: Parameters: nil and ReturnParameters: uint256 Actual: Paramters: uint256 and ReturnParameters: uint256

The source of this bug is likely the lines below, where we are getting the params fron AllParameterList instead of GetArguments. https://github.com/unpackdev/solgo/blob/aa00b43da981742fa9670f0323b838e1bf77e6ef/ast/function.go#L430 https://github.com/unpackdev/solgo/blob/aa00b43da981742fa9670f0323b838e1bf77e6ef/ast/function.go#L534

Suggestion

We can change it from

if len(ctx.AllParameterList()) > 0 {
        params.Parse(unit, f, ctx.AllParameterList()[0])

to

if ctx.GetArguments() != nil {
        params.Parse(unit, f, ctx.GetArguments())
xianlinc commented 5 months ago

This fix is not urgent as I have applied a fix that works for my use case of the library already! Please don't feel rushed to fix this 😎