bug(`compiler`): the `ether` keyword breaks forge scripts when ran as `forge script Foo`
zaqk opened this issue · 5 comments
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 (27cabbd 2024-11-29T00:28:06.641192000Z)
What command(s) is the bug in?
forge script
Operating System
macOS (Apple Silicon)
Describe the bug
it seems the use of the ether
keyword anywhere in a forge script contract will cause break forge script.
My code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import {Script} from "forge-std/Script.sol";
contract POC is Script {
function run() external {
uint256 a = .1 ether;
}
}
The error:
▶ forge script POC
Error: No contract found with the name `POC`
a workaround is to just not use the keyword.
Workaround code:
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.10;
import {Script} from "forge-std/Script.sol";
contract POC is Script {
function run() external {
uint256 a = 1e17;
}
}
console output
▶ forge script POC
[⠊] Compiling...
No files changed, compilation skipped
Script ran successfully.
Gas used: 21161
Hi @zaqk thanks for the bug report
I'm able to reproduce it with the given setup and it appears to be a regression
Update: appears to be related to a change introduced in #9346 or #8668 + https://github.com/foundry-rs/compilers
Fails: git checkout c13d42e850da353c0856a8b0d4123e13cc40045d
Works: git checkout e649e62f125244a3ef116be25dfdc81a2afbaf2a
cc @klkvr
It is not exactly clear why the ether
keyword (no inlining / dead code elimination?) is relevant here but running it as forge script script/POC.s.sol
this works as expected
Re-rating to p-low
given that there is a workaround and only occurs in some edge cases
also worth noting i didnt run into the issue if i used 1 ether
.
Upstream fixes: