@@ -289,10 +289,16 @@ impl RegisterExt for Register {
289
289
}
290
290
291
291
fn modify_field ( & mut self , fspec : & str , fmod : & Hash , rpath : & RegisterPath ) -> PatchResult {
292
+ let ( fspec, ignore) = fspec. spec ( ) ;
292
293
let ftags = self . iter_fields ( fspec) . collect :: < Vec < _ > > ( ) ;
293
294
let field_builder = make_field ( fmod, Some ( rpath) ) ?;
294
295
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 {
296
302
for ftag in ftags {
297
303
modify_dim_element ( ftag, & dim) ?;
298
304
if let Some ( value) = fmod
@@ -362,28 +368,39 @@ impl RegisterExt for Register {
362
368
dpath. into ( )
363
369
}
364
370
}
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
+ )
367
377
} else if let Some ( hash) = fderive. as_hash ( ) {
368
378
let dpath = hash. get_str ( "_from" ) ?. ok_or_else ( || {
369
379
anyhow ! ( "derive: source field not given, please add a _from field to {fspec}" )
370
380
} ) ?;
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
+ )
372
385
} else {
373
386
return Err ( anyhow ! ( "derive: incorrect syntax for {fspec}" ) ) ;
374
387
} ;
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
+ } ) ;
387
404
}
388
405
Ok ( ( ) )
389
406
}
0 commit comments