Repository navigation
Accept '$' in @param and @return names - #486
Open
pucedoteth wants to merge 1 commit into
Open
pucedoteth wants to merge 1 commit into
pucedoteth wants to merge 1 commit into
Conversation
Solidity identifiers may contain '$', but both NatSpec tag parsers matched the name with \w+, which does not. ERC-7201 namespaced storage conventionally names its struct pointer '$', so `@return $ ...` raised "Expected @return tag to start with name '$'", and `@param a$b ...` silently parsed the name as 'b' and dropped the description. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #464.
The bug
Solidity identifiers may contain
$([a-zA-Z$_][a-zA-Z0-9$_]*), but both NatSpec tag parsers matched the name with\w+, which is[A-Za-z0-9_]:\w+cannot match$, so the regex skips past it and captures the next word instead. The consequences differ by tag:@return$ the storage structStorageExpected @return tag to start with name '$'@param$c the operandthe@parama$b the operandbThe
@returncase is the one reported in #464. The@paramcase is quieter and arguably worse: nothing throws, the name simply fails to match the parameter ingetParams, and the description is dropped from the generated docs without any error.This shows up in practice because ERC-7201 namespaced storage conventionally names its struct pointer
$, so documenting an accessor is enough to trigger it:The change
One shared pattern, used by both tags:
_-prefixed and alphanumeric names parse exactly as before;$,$fooanda$bnow parse correctly.Tests
test-contracts/S08_Dollar.solcovers@return $,@param a$b,@param $cand@return $d, and the render test asserts that each description attaches to the right parameter — so it catches the silent@paramcase as well as the throw.One small change to the test helper was needed to make this testable at all:
testRendercalledbuildSite(build, cfg)without the thirdpropertiesargument, so the computedparams/returns/itemsgetters were never attached and any template touching them rendered empty. It now forwardsspec.properties ?? {}, which is whatmain.tsdoes and is a no-op for the existing tests.Reverting only
src/utils/natspec.tsand keeping the tests:With the fix,
npm testis 9 tests passed, andtsc --noEmitis clean.AI disclosure
Written with AI assistance (Claude Code): the investigation, the fix, the tests, and this description.
🤖 Generated with Claude Code