@@ -211,7 +211,7 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
211
211
if pe .Equals (rhsPEs [rI ]) {
212
212
// merge LHS & RHS items
213
213
mergedRHS .Insert (pe , struct {}{})
214
- lChild , _ := observedLHS .Get (pe )
214
+ lChild , _ := observedLHS .Get (pe ) // may be nil if the PE is duplicaated.
215
215
rChild , _ := observedRHS .Get (pe )
216
216
mergeOut , errs := w .mergeListItem (t , pe , lChild , rChild )
217
217
errs = append (errs , errs ... )
@@ -237,7 +237,7 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
237
237
if lI < lLen {
238
238
pe := lhsPEs [lI ]
239
239
if _ , ok := observedRHS .Get (pe ); ! ok {
240
- // take LHS item
240
+ // take LHS item using At to make sure we get the right item (observed may not contain the right item).
241
241
lChild := lhs .AtUsing (w .allocator , lI )
242
242
mergeOut , errs := w .mergeListItem (t , pe , lChild , nil )
243
243
errs = append (errs , errs ... )
@@ -255,7 +255,7 @@ func (w *mergingWalker) visitListItems(t *schema.List, lhs, rhs value.List) (err
255
255
// Take the RHS item, merge with matching LHS item if possible
256
256
pe := rhsPEs [rI ]
257
257
mergedRHS .Insert (pe , struct {}{})
258
- lChild , _ := observedLHS .Get (pe ) // may be nil
258
+ lChild , _ := observedLHS .Get (pe ) // may be nil if absent or duplicaated.
259
259
rChild , _ := observedRHS .Get (pe )
260
260
mergeOut , errs := w .mergeListItem (t , pe , lChild , rChild )
261
261
errs = append (errs , errs ... )
@@ -305,6 +305,9 @@ func (w *mergingWalker) indexListPathElements(t *schema.List, list value.List, a
305
305
continue
306
306
} else if ! found {
307
307
observed .Insert (pe , child )
308
+ } else {
309
+ // Duplicated items are not merged with the new value, make them nil.
310
+ observed .Insert (pe , value .NewValueInterface (nil ))
308
311
}
309
312
pes = append (pes , pe )
310
313
}
0 commit comments