solhint icon indicating copy to clipboard operation
solhint copied to clipboard

Parser crashes with TypeError when visiting contract parts

Open kaypee90 opened this issue 1 month ago • 5 comments

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

kaypee90 avatar Nov 20 '25 19:11 kaypee90

I'll be checking this! Thanks @kaypee90 for reporting this

dbale-altoros avatar Nov 26 '25 15:11 dbale-altoros

@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 avatar Nov 26 '25 15:11 dbale-altoros

@dbale-altoros https://github.com/solidity-parser/parser/issues/116 is a related issue

kaypee90 avatar Nov 27 '25 02:11 kaypee90

I am using solhint 6.0.1

kaypee90 avatar Nov 27 '25 02:11 kaypee90

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

dbale-altoros avatar Nov 27 '25 13:11 dbale-altoros