@@ -289,10 +289,16 @@ impl RegisterExt for Register {
289289 }
290290
291291 fn modify_field ( & mut self , fspec : & str , fmod : & Hash , rpath : & RegisterPath ) -> PatchResult {
292+ let ( fspec, ignore) = fspec. spec ( ) ;
292293 let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
293294 let field_builder = make_field ( fmod, Some ( rpath) ) ?;
294295 let dim = make_dim_element ( fmod) ?;
295- if !ftags. is_empty ( ) {
296+ if ftags. is_empty ( ) && !ignore {
297+ let present = self . present_fields ( ) ;
298+ return Err ( anyhow ! (
299+ "Could not find `{rpath}:{fspec}. Present fields: {present}.`"
300+ ) ) ;
301+ } else {
296302 for ftag in ftags {
297303 modify_dim_element ( ftag, & dim) ?;
298304 if let Some ( value) = fmod
@@ -362,6 +368,7 @@ impl RegisterExt for Register {
362368 dpath. into ( )
363369 }
364370 }
371+ let ( fspec, ignore) = fspec. spec ( ) ;
365372 let info = if let Some ( dpath) = fderive. as_str ( ) {
366373 FieldInfo :: builder ( ) . derived_from ( Some ( make_path ( dpath, rpath) ) )
367374 } else if let Some ( hash) = fderive. as_hash ( ) {
@@ -372,18 +379,15 @@ impl RegisterExt for Register {
372379 } else {
373380 return Err ( anyhow ! ( "derive: incorrect syntax for {fspec}" ) ) ;
374381 } ;
375-
376- let mut found = false ;
377- for field in self . iter_fields ( fspec) {
378- found = true ;
379- field. modify_from ( info. clone ( ) , VAL_LVL ) ?;
380- }
381- if !found {
382- {
383- super :: check_dimable_name ( fspec) ?;
384- let field = info. name ( fspec. into ( ) ) . build ( VAL_LVL ) ?. single ( ) ;
385- self . fields . get_or_insert ( Vec :: new ( ) ) . push ( field) ;
382+ let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
383+ if !ftags. is_empty ( ) {
384+ for field in ftags {
385+ field. modify_from ( info. clone ( ) , VAL_LVL ) ?;
386386 }
387+ } else if !ignore {
388+ super :: check_dimable_name ( fspec) ?;
389+ let field = info. name ( fspec. into ( ) ) . build ( VAL_LVL ) ?. single ( ) ;
390+ self . fields . get_or_insert ( Vec :: new ( ) ) . push ( field) ;
387391 }
388392 Ok ( ( ) )
389393 }
0 commit comments