Skip to content

Parser crashes with TypeError when visiting contract parts #725

@kaypee90

Description

@kaypee90

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions