iamdefinitelyahuman / py-solc-ast

A tool for exploring the solc abstract syntax tree
MIT License
37 stars 10 forks source link

"using something for *" does not parse successfully #23

Closed zomglings closed 9 months ago

zomglings commented 2 years ago

Environment information

What was wrong?

Please include information like:

I initialized this repo as a brownie project: https://github.com/darkforest-eth/eth

And went to compile it, only to get the following error message:

$ brownie compile
Brownie v1.18.1 - Python development framework for Ethereum

New compatible solc version available: 0.8.9
Compiling contracts...
  Solc version: 0.8.9
  Optimizer: Enabled  Runs: 200
  EVM Version: Istanbul
Generating build data...
  File "brownie/_cli/__main__.py", line 64, in main
    importlib.import_module(f"brownie._cli.{cmd}").main()
  File "brownie/_cli/compile.py", line 50, in main
    proj = project.load()
  File "brownie/project/main.py", line 768, in load
    return Project(name, project_path)
  File "brownie/project/main.py", line 188, in __init__
    self.load()
  File "brownie/project/main.py", line 245, in load
    self._compile(changed, self._compiler_config, False)
  File "brownie/project/main.py", line 100, in _compile
    build_json = compiler.compile_and_format(
  File "brownie/project/compiler/__init__.py", line 142, in compile_and_format
    build_json.update(generate_build_json(input_json, output_json, compiler_data, silent))
  File "brownie/project/compiler/__init__.py", line 287, in generate_build_json
    source_nodes, statement_nodes, branch_nodes = solidity._get_nodes(output_json)
  File "brownie/project/compiler/solidity.py", line 606, in _get_nodes
    source_nodes = solcast.from_standard_output(output_json)
  File "solcast/main.py", line 33, in from_standard_output
    source_nodes = set_dependencies(source_nodes)
  File "solcast/dependencies.py", line 18, in set_dependencies
    contract.libraries = dict(
  File "solcast/dependencies.py", line 19, in <genexpr>
    (_get_type_name(i.typeName), i.libraryName.name)
AttributeError: 'UsingForDirective' object has no attribute 'typeName'

How can it be fixed?

We need to parse UsingForDirective AST nodes according to this specification: https://docs.soliditylang.org/en/v0.8.13/contracts.html#using-for

I haven't personally used using something for * before, so I will do some thinking about the right way to handle it in the solc-ast codebase. Are you actively maintaining this repo? Do you accept PRs?