@@ -350,21 +350,7 @@ impl TypeDef {
350
350
351
351
pub fn merge ( & mut self , other : Self , strategy : merge:: Strategy ) {
352
352
self . fallible |= other. fallible ;
353
-
354
- // NOTE: technically we shouldn't do this, but to keep backward compatibility with the
355
- // "old" `Kind` implementation, we consider a type that is marked as "any" equal to the old
356
- // implementation's `unknown`, which, when merging, would discard that type.
357
- //
358
- // see: https://github.com/vectordotdev/vector/blob/18415050b60b08197e8135b7659390256995e844/lib/vrl/compiler/src/type_def.rs#L428-L429
359
- if !self . is_any ( ) && other. is_any ( ) {
360
- // keep `self`'s `kind` definition
361
- } else if self . is_any ( ) && !other. is_any ( ) {
362
- // overwrite `self`'s `kind` definition with `others`'s
363
- self . kind = other. kind ;
364
- } else {
365
- // merge the two `kind`s
366
- self . kind . merge ( other. kind , strategy) ;
367
- }
353
+ self . kind . merge ( other. kind , strategy) ;
368
354
}
369
355
370
356
pub fn merge_overwrite ( mut self , other : Self ) -> Self {
@@ -399,3 +385,78 @@ pub(crate) struct Details {
399
385
pub ( crate ) type_def : TypeDef ,
400
386
pub ( crate ) value : Option < Value > ,
401
387
}
388
+
389
+ impl Details {
390
+ /// Returns the union of 2 possible states
391
+ #[ cfg( any( test, feature = "expr-if_statement" ) ) ]
392
+ pub ( crate ) fn merge ( self , other : Self ) -> Self {
393
+ Self {
394
+ type_def : self . type_def . merge_deep ( other. type_def ) ,
395
+ value : if self . value == other. value {
396
+ self . value
397
+ } else {
398
+ None
399
+ } ,
400
+ }
401
+ }
402
+
403
+ /// Returns the union of 2 possible states
404
+ #[ cfg( any( feature = "expr-if_statement" ) ) ]
405
+ pub ( crate ) fn merge_optional (
406
+ a : Option < Self > ,
407
+ b : Option < Self > ,
408
+ none_type : TypeDef ,
409
+ ) -> Option < Self > {
410
+ match ( a, b) {
411
+ ( Some ( a) , Some ( b) ) => Some ( a. merge ( b) ) ,
412
+ ( Some ( _) , None ) | ( None , Some ( _) ) => Some ( Details {
413
+ type_def : none_type,
414
+ value : None ,
415
+ } ) ,
416
+ ( None , None ) => None ,
417
+ }
418
+ }
419
+ }
420
+
421
+ #[ cfg( test) ]
422
+ mod test {
423
+ use super :: * ;
424
+
425
+ #[ test]
426
+ fn merge_details_same_literal ( ) {
427
+ let a = Details {
428
+ type_def : TypeDef :: integer ( ) ,
429
+ value : Some ( Value :: from ( 5 ) ) ,
430
+ } ;
431
+ let b = Details {
432
+ type_def : TypeDef :: float ( ) ,
433
+ value : Some ( Value :: from ( 5 ) ) ,
434
+ } ;
435
+ assert_eq ! (
436
+ a. merge( b) ,
437
+ Details {
438
+ type_def: TypeDef :: integer( ) . add_float( ) ,
439
+ value: Some ( Value :: from( 5 ) )
440
+ }
441
+ )
442
+ }
443
+
444
+ #[ test]
445
+ fn merge_details_different_literal ( ) {
446
+ let a = Details {
447
+ type_def : TypeDef :: any ( ) ,
448
+ value : Some ( Value :: from ( 5 ) ) ,
449
+ } ;
450
+ let b = Details {
451
+ type_def : TypeDef :: object ( Collection :: empty ( ) ) ,
452
+ value : Some ( Value :: from ( 6 ) ) ,
453
+ } ;
454
+ assert_eq ! (
455
+ a. merge( b) ,
456
+ Details {
457
+ type_def: TypeDef :: any( ) ,
458
+ value: None
459
+ }
460
+ )
461
+ }
462
+ }
0 commit comments