solidity-docgen icon indicating copy to clipboard operation
solidity-docgen copied to clipboard

Do not expect that first word in comment line is name of result variable

Open Pzixel opened this issue 3 years ago • 5 comments

Consider following method and comment:

/// @return Some value
function foo() external view returns(uint256) {
    return 0;
}

When it get parsed with parseNatSpec function it parses Some as response variable name and the rest as its description. But natspec doesn't have any requirements on format of return and it makes total sense to omit it at all when there is only one return value

Pzixel avatar Jun 10 '21 14:06 Pzixel

There is a comment about its format:

If your function returns multiple values, like (int quotient, int remainder) then use multiple @return statements in the same format as the @param statements.

But their own example with Tree shows that it only applies when function has more than one output value

Pzixel avatar Jun 10 '21 15:06 Pzixel

Thanks for pointing this out. We're indeed assuming the wrong format in our parsing.

frangio avatar Jun 10 '21 18:06 frangio

It seems that if the function declares names for return values (as in returns (uint a)) then the NatSpec syntax expects the variable name, otherwise it doesn't.

frangio avatar Jan 04 '22 17:01 frangio

Right, but it still should possible to add comment to function result, even if it's anonymous. It should be then somehing like:

result.name // undefined
result.description // 'Some value'

Pzixel avatar Jan 04 '22 17:01 Pzixel

Yes, I was able to reproduce the behavior implemented by solc.

frangio avatar Jan 05 '22 02:01 frangio