@@ -16,7 +16,7 @@ use forge::{
1616use foundry_cli:: utils:: { LoadConfig , STATIC_FUZZ_SEED } ;
1717use foundry_common:: { compile:: ProjectCompiler , fs} ;
1818use foundry_compilers:: {
19- artifacts:: { sourcemap:: SourceMap , CompactBytecode , CompactDeployedBytecode } ,
19+ artifacts:: { sourcemap:: SourceMap , CompactBytecode , CompactDeployedBytecode , SolcLanguage } ,
2020 Artifact , ArtifactId , Project , ProjectCompileOutput ,
2121} ;
2222use foundry_config:: { Config , SolcReq } ;
@@ -94,23 +94,12 @@ impl CoverageArgs {
9494 // Set up the project
9595 let mut project = config. create_project ( false , false ) ?;
9696 if self . ir_minimum {
97- // TODO: How to detect solc version if the user does not specify a solc version in
98- // config case1: specify local installed solc ?
99- // case2: multiple solc versions used and auto_detect_solc == true
100- if let Some ( SolcReq :: Version ( version) ) = & config. solc {
101- if * version < Version :: new ( 0 , 8 , 13 ) {
102- return Err ( eyre:: eyre!(
103- "viaIR with minimum optimization is only available in Solidity 0.8.13 and above."
104- ) ) ;
105- }
106- }
107-
10897 // print warning message
10998 sh_warn ! ( "{}" , concat!(
110- "Warning! \" --ir-minimum\" flag enables viaIR with minimum optimization, \
99+ "` --ir-minimum` enables viaIR with minimum optimization, \
111100 which can result in inaccurate source mappings.\n ",
112101 "Only use this flag as a workaround if you are experiencing \" stack too deep\" errors.\n " ,
113- "Note that \" viaIR\" is only available in Solidity 0.8.13 and above.\n " ,
102+ "Note that \" viaIR\" is production ready since Solidity 0.8.13 and above.\n " ,
114103 "See more: https://github.com/foundry-rs/foundry/issues/3357" ,
115104 ) ) ?;
116105
@@ -119,7 +108,15 @@ impl CoverageArgs {
119108 // And also in new releases of solidity:
120109 // https://github.com/ethereum/solidity/issues/13972#issuecomment-1628632202
121110 project. settings . solc . settings =
122- project. settings . solc . settings . with_via_ir_minimum_optimization ( )
111+ project. settings . solc . settings . with_via_ir_minimum_optimization ( ) ;
112+ let version = if let Some ( SolcReq :: Version ( version) ) = & config. solc {
113+ version
114+ } else {
115+ // Sanitize settings for solc 0.8.4 if version cannot be detected.
116+ // See <https://github.com/foundry-rs/foundry/issues/9322>.
117+ & Version :: new ( 0 , 8 , 4 )
118+ } ;
119+ project. settings . solc . settings . sanitize ( version, SolcLanguage :: Solidity ) ;
123120 } else {
124121 project. settings . solc . optimizer . disable ( ) ;
125122 project. settings . solc . optimizer . runs = None ;
0 commit comments