@@ -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,28 +368,39 @@ impl RegisterExt for Register {
362368 dpath. into ( )
363369 }
364370 }
365- let info = if let Some ( dpath) = fderive. as_str ( ) {
366- FieldInfo :: builder ( ) . derived_from ( Some ( make_path ( dpath, rpath) ) )
371+ let ( fspec, ignore) = fspec. spec ( ) ;
372+ let ( dim, info) = if let Some ( dpath) = fderive. as_str ( ) {
373+ (
374+ None ,
375+ FieldInfo :: builder ( ) . derived_from ( Some ( make_path ( dpath, rpath) ) ) ,
376+ )
367377 } else if let Some ( hash) = fderive. as_hash ( ) {
368378 let dpath = hash. get_str ( "_from" ) ?. ok_or_else ( || {
369379 anyhow ! ( "derive: source field not given, please add a _from field to {fspec}" )
370380 } ) ?;
371- make_field ( hash, Some ( rpath) ) ?. derived_from ( Some ( make_path ( dpath, rpath) ) )
381+ (
382+ make_dim_element ( hash) ?,
383+ make_field ( hash, Some ( rpath) ) ?. derived_from ( Some ( make_path ( dpath, rpath) ) ) ,
384+ )
372385 } else {
373386 return Err ( anyhow ! ( "derive: incorrect syntax for {fspec}" ) ) ;
374387 } ;
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) ;
386- }
388+ let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
389+ if !ftags. is_empty ( ) {
390+ for ftag in ftags {
391+ modify_dim_element ( ftag, & dim) ?;
392+ ftag. modify_from ( info. clone ( ) , VAL_LVL ) ?;
393+ }
394+ } else if !ignore {
395+ super :: check_dimable_name ( fspec) ?;
396+ let field = info. name ( fspec. into ( ) ) . build ( VAL_LVL ) ?;
397+ self . fields . get_or_insert ( Vec :: new ( ) ) . push ( {
398+ if let Some ( dim) = dim {
399+ field. array ( dim. build ( VAL_LVL ) ?)
400+ } else {
401+ field. single ( )
402+ }
403+ } ) ;
387404 }
388405 Ok ( ( ) )
389406 }
0 commit comments