Skip to content

No warnings emitted when auto-detection corrects incorrect import paths #9299

Open
@samooyo

Description

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (e028b92 2024-11-11T00:22:42.074556087Z)

What command(s) is the bug in?

forge build

Operating System

Linux

Describe the bug

When Foundry encounters an incorrect import path in a contract, it appears to automatically correct it without emitting any warnings or notifications. This silent correction prevents developers from being aware that there was an issue with the original import path, which could lead to confusion or unintended behavior.

In my case, there was a double slash in the path of an import (//), which made it difficult to debug. I was using the OpenZeppelin Upgrades plugin to deploy a proxy with my contract, and during the validation step, I encountered an unexpected error: Cannot read properties of undefined (reading 'ast'). This error was caused by OpenZeppelin not finding the specified import, even though everything was compiling correctly.

I've created a minimal example to demonstrate this error here.
You can see that in src/TestContract.sol, line 4, the import is: import "@openzeppelin/contracts-upgradeable//proxy/utils/Initializable.sol"; but still compile.

Expected Behavior

If an import path is detected as incorrect, a warning should be emitted to inform the user of the original issue before auto-correcting it. This would allow developers to address the root cause of the path issue directly.

Steps to Reproduce

  1. Clone the repo: git clone https://github.com/samooyo/foundry-bug-report.git
  2. Run the script: forge script script/Deploy.s.sol

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    • Status

      Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions