Parser crashes with TypeError when visiting contract parts
Solhint crashes with a TypeError: Cannot read properties of null (reading 'accept') when attempting to parse Solidity files. The error occurs during AST building when visiting contract parts
Steps to Reproduce
I experienced this error when I ran solhint on https://github.com/paritytech/polkadot-sdk
*Run solhint with the following command:
solhint ./**/*.sol -c solhint.json -f json --disc
The parser crashes before completing the scan
Error Output
[solhint] Warning: Rule 'custom-errors' doesn't exist
[solhint] Warning: Rule 'contract-name-camelcase' doesn't exist
[solhint] Warning: Rule 'event-name-camelcase' doesn't exist
[solhint] Warning: Rule 'named-return-values' doesn't exist
TypeError: Cannot read properties of null (reading 'accept')
at ASTBuilder.visit (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:3236:19)
at ASTBuilder.visitContractPart (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:38463:17)
at ContractPartContext.accept (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:35068:22)
at ASTBuilder.visit (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:3236:19)
at /opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:38477:58
at Array.map (<anonymous>)
at ASTBuilder.visitContractDefinition (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:38477:41)
at ContractDefinitionContext.accept (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:34951:22)
at ASTBuilder.visit (/opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:3236:19)
at /opt/homebrew/lib/node_modules/solhint/node_modules/@solidity-parser/parser/dist/index.cjs.js:38456:59
The error occurs in the @solidity-parser/parser dependency when building the AST. The parser encounters a null node when attempting to visit contract parts, suggesting it may be related to:
- Incomplete or malformed contract syntax
- Unsupported Solidity language features
- Edge cases in the parser's handling of certain contract structures
I'll be checking this! Thanks @kaypee90 for reporting this
@kaypee90 do you have the last parser ?
https://www.npmjs.com/package/@solidity-parser/parser 0.20.2 • Public • Published 4 months ago
As you mentioned, seems like it is parser related, so nothing much to do here if that is the case It will be good to identify which is the file causing issues Can you do that ?
maybe for faster check
for f in $(find . -name '*.sol'); do
echo ">> $f"
npx solhint "$f" || break
done
Check also this issue on the parser repo (116) Seems to be the same issue... not sure though
@dbale-altoros https://github.com/solidity-parser/parser/issues/116 is a related issue
I am using solhint 6.0.1
I am using solhint 6.0.1
I meant parser version Because if you have previous version, solhint could work, but newer solidity syntax could fail Check the parser package version https://www.npmjs.com/package/@solidity-parser/parser