Skip to content

Commit

Permalink
Don't merge objects that point at each other
Browse files Browse the repository at this point in the history
  • Loading branch information
lkarlslund committed Nov 9, 2022
1 parent 96ad47a commit 9d8b866
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions modules/engine/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,15 +310,36 @@ func (os *Objects) Merge(attrtomerge []Attribute, source *Object) bool {

if mergetargets, found := os.FindMulti(mergeattr, lookfor); found {
mergetargets.Iterate(func(target *Object) bool {
var failed bool
targetType := target.Type()

// Test if types mismatch violate this merge
targetType := target.Type()
if targetType != ObjectTypeOther && sourceType != ObjectTypeOther && targetType != sourceType {
// Merge conflict, can't merge different types
ui.Trace().Msgf("Merge failure due to type difference, not merging %v of type %v with %v of type %v", source.Label(), sourceType.String(), target.Label(), targetType.String())
failed = true
return false
return false // continue
}

var failed bool

// Test if there are incoming or outgoing edges pointing at each other
source.edges[In].Range(func(pointingFrom *Object, value EdgeBitmap) bool {
if target == pointingFrom {
failed = true
return false
}
return true
})
if failed {
return false // continue
}
source.edges[Out].Range(func(pointingTo *Object, value EdgeBitmap) bool {
if target == pointingTo {
failed = true
return false
}
return true
})
if failed {
return false // continue
}

// Test if any single attribute holding values violate this merge
Expand Down

0 comments on commit 9d8b866

Please sign in to comment.