alloy-rs / core

High-performance, well-tested & documented core libraries for Ethereum, in Rust
https://alloy.rs
Apache License 2.0
763 stars 137 forks source link

[Bug] remapped types with `sol!` macro with file reference broken #621

Closed austinabell closed 3 months ago

austinabell commented 4 months ago

Component

sol! macro

What version of Alloy are you on?

regression was from 0.6.1 (commit a315b0d22f37e8c15af84fed0bd553ea10fd1fbd)

Operating System

None

Describe the bug

Bisecting versions and commits, the regression happened on 0.6.0..0.6.1 on this commit https://github.com/alloy-rs/core/commit/a315b0d22f37e8c15af84fed0bd553ea10fd1fbd

The contract is pretty simple where sol! is pointing at a sol file, and the type not found is referencing something remapped in the remappings.txt.

Error looks like:

error[E0412]: cannot find type `IContract` in this scope
 --> crates/service/src/contract.rs:3:1
  |
3 | sol!("../../contracts/Renamed.sol");
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
DaniPopes commented 3 months ago

It just so happens that only your constructor has references to types not defined in the same file, and now it got exposed because we parse constructors. This is not a regression, we're simply considering more code and this behavior was never allowed.

Consider using JSON ABI or defining a separate interface manually.