@@ -96,7 +96,7 @@ enum BytecodeDependencyKind {
9696 /// `type(Contract).creationCode`
9797 CreationCode ,
9898 /// `new Contract`. Holds the name of the contract and args length.
99- New ( String , usize ) ,
99+ New ( String , usize , usize ) ,
100100}
101101
102102/// Represents a single bytecode dependency.
@@ -173,18 +173,26 @@ impl<'hir> Visit<'hir> for BytecodeDependencyCollector<'hir> {
173173
174174 fn visit_expr ( & mut self , expr : & ' hir Expr < ' hir > ) -> ControlFlow < Self :: BreakValue > {
175175 match & expr. kind {
176- ExprKind :: Call ( ty, _ , _ ) => {
176+ ExprKind :: Call ( ty, call_args , named_args ) => {
177177 if let ExprKind :: New ( ty_new) = & ty. kind {
178178 if let TypeKind :: Custom ( item_id) = ty_new. kind {
179179 if let Some ( contract_id) = item_id. as_contract ( ) {
180180 let name_loc =
181181 SourceMapLocation :: from_span ( self . source_map , ty_new. span ) ;
182182 let name = & self . src [ name_loc. start ..name_loc. end ] ;
183+
184+ let offset = if named_args. is_some ( ) && !call_args. is_empty ( ) {
185+ ( call_args. span ( ) . lo ( ) - ty_new. span . hi ( ) ) . to_usize ( ) - 1
186+ } else {
187+ 0
188+ } ;
189+
183190 let args_len = expr. span . hi ( ) - ty_new. span . hi ( ) ;
184191 self . collect_dependency ( BytecodeDependency {
185192 kind : BytecodeDependencyKind :: New (
186193 name. to_string ( ) ,
187194 args_len. to_usize ( ) ,
195+ offset,
188196 ) ,
189197 loc : SourceMapLocation :: from_span ( self . source_map , ty. span ) ,
190198 referenced_contract : contract_id,
@@ -252,7 +260,7 @@ pub(crate) fn remove_bytecode_dependencies(
252260 format ! ( "{vm}.getCode(\" {artifact}\" )" ) ,
253261 ) ) ;
254262 }
255- BytecodeDependencyKind :: New ( name, args_length) => {
263+ BytecodeDependencyKind :: New ( name, args_length, offset ) => {
256264 if constructor_data. is_none ( ) {
257265 // if there's no constructor, we can just call deployCode with one
258266 // argument
@@ -266,7 +274,7 @@ pub(crate) fn remove_bytecode_dependencies(
266274 used_helpers. insert ( dep. referenced_contract ) ;
267275 updates. insert ( (
268276 dep. loc . start ,
269- dep. loc . end ,
277+ dep. loc . end + offset ,
270278 format ! (
271279 "deployCode{id}(DeployHelper{id}.ConstructorArgs" ,
272280 id = dep. referenced_contract. get( )
0 commit comments