@@ -95,8 +95,8 @@ impl PreprocessorDependencies {
9595enum BytecodeDependencyKind {
9696 /// `type(Contract).creationCode`
9797 CreationCode ,
98- /// `new Contract`. Holds the name of the contract, args length and offset, `msg.value` (if
99- /// any) and salt (if any).
98+ /// `new Contract`. Holds the name of the contract, args length and call args offset,
99+ /// `msg.value` (if any) and salt (if any).
100100 New ( String , usize , usize , Option < String > , Option < String > ) ,
101101}
102102
@@ -182,8 +182,12 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
182182 SourceMapLocation :: from_span ( self . source_map , ty_new. span ) ;
183183 let name = & self . src [ name_loc. start ..name_loc. end ] ;
184184
185- let offset = if named_args. is_some ( ) && !call_args. is_empty ( ) {
186- ( call_args. span ( ) . lo ( ) - ty_new. span . hi ( ) ) . to_usize ( ) - 1
185+ // Calculate offset to remove named args, e.g. for an expression like
186+ // `new Counter {value: 333} ( address(this))`
187+ // the offset will be used to replace `{value: 333} ( ` with `(`
188+ let call_args_offset = if named_args. is_some ( ) && !call_args. is_empty ( )
189+ {
190+ ( call_args. span ( ) . lo ( ) - ty_new. span . hi ( ) ) . to_usize ( )
187191 } else {
188192 0
189193 } ;
@@ -193,7 +197,7 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
193197 kind : BytecodeDependencyKind :: New (
194198 name. to_string ( ) ,
195199 args_len. to_usize ( ) ,
196- offset ,
200+ call_args_offset ,
197201 named_arg ( self . src , named_args, "value" , self . source_map ) ,
198202 named_arg ( self . src , named_args, "salt" , self . source_map ) ,
199203 ) ,
@@ -278,7 +282,7 @@ pub(crate) fn remove_bytecode_dependencies(
278282 format ! ( "{vm}.getCode(\" {artifact}\" )" ) ,
279283 ) ) ;
280284 }
281- BytecodeDependencyKind :: New ( name, args_length, offset , value, salt) => {
285+ BytecodeDependencyKind :: New ( name, args_length, call_args_offset , value, salt) => {
282286 let mut update = format ! ( "{name}(payable({vm}.deployCode({{" ) ;
283287 update. push_str ( & format ! ( "_artifact: \" {artifact}\" " ) ) ;
284288
@@ -301,7 +305,10 @@ pub(crate) fn remove_bytecode_dependencies(
301305 "_args: encodeArgs{id}(DeployHelper{id}.ConstructorArgs" ,
302306 id = dep. referenced_contract. get( )
303307 ) ) ;
304- updates. insert ( ( dep. loc . start , dep. loc . end + offset, update) ) ;
308+ if * call_args_offset > 0 {
309+ update. push ( '(' ) ;
310+ }
311+ updates. insert ( ( dep. loc . start , dep. loc . end + call_args_offset, update) ) ;
305312 updates. insert ( (
306313 dep. loc . end + args_length,
307314 dep. loc . end + args_length,
0 commit comments