Reset inherited YAML identity on actual replacement
This commit is contained in:
@@ -59,6 +59,7 @@ func inheritanceCollectionResolution(
|
||||
path Path,
|
||||
lowerScope, higherScope collectionPolicyScope,
|
||||
applicationPolicy sequencePolicy,
|
||||
incoming *document.Node,
|
||||
) (collectionPolicyResolution, collectionPolicy, collectionPolicy, bool, []Diagnostic) {
|
||||
lower, hasLower := lowerScope.at(path)
|
||||
higher, hasHigher := higherScope.at(path)
|
||||
@@ -72,6 +73,11 @@ func inheritanceCollectionResolution(
|
||||
lowerForResolution.explicitMode = 0
|
||||
lowerForResolution.explicitModePresent = false
|
||||
lowerForResolution.modeLocation = nil
|
||||
if incoming != nil && higher.explicitModePresent && higher.explicitMode == sequenceModeReplace {
|
||||
// Actual replacement discards the parent's YAML identity before
|
||||
// agreement. A mode-only declaration still governs retained records.
|
||||
lowerForResolution = collectionPolicy{}
|
||||
}
|
||||
var lowerPointer *collectionPolicy
|
||||
if hasLower {
|
||||
lowerPointer = &lowerForResolution
|
||||
@@ -85,7 +91,7 @@ func inheritanceCollectionResolution(
|
||||
func mergeInheritanceCollectionPolicies(
|
||||
parent, child collectionPolicyScope,
|
||||
parentRootPath Path,
|
||||
parentValue *document.Node,
|
||||
parentValue, childValue *document.Node,
|
||||
applicationPolicy sequencePolicy,
|
||||
) (collectionPolicyScope, []Diagnostic) {
|
||||
result := cloneCollectionPolicyScopeForInheritance(parent)
|
||||
@@ -98,7 +104,13 @@ func mergeInheritanceCollectionPolicies(
|
||||
}
|
||||
var diagnostics []Diagnostic
|
||||
for _, path := range paths {
|
||||
resolution, lower, _, active, issues := inheritanceCollectionResolution(path, parent, child, applicationPolicy)
|
||||
relative, inside := relativeHistoryPath(parentRootPath, path)
|
||||
var retained, incoming *document.Node
|
||||
if inside {
|
||||
retained, _ = documentAtPath(parentValue, relative)
|
||||
incoming, _ = documentAtPath(childValue, relative)
|
||||
}
|
||||
resolution, lower, _, active, issues := inheritanceCollectionResolution(path, parent, child, applicationPolicy, incoming)
|
||||
if len(issues) != 0 {
|
||||
diagnostics = append(diagnostics, issues...)
|
||||
continue
|
||||
@@ -113,15 +125,14 @@ func mergeInheritanceCollectionPolicies(
|
||||
lower.modeLocation = nil
|
||||
lowerPointer = &lower
|
||||
}
|
||||
relative, inside := relativeHistoryPath(parentRootPath, path)
|
||||
var retained *document.Node
|
||||
if inside {
|
||||
retained, _ = documentAtPath(parentValue, relative)
|
||||
}
|
||||
policy, foundDiagnostics := collectionPolicyWithoutValue(lowerPointer, resolution.policy, retained, path)
|
||||
if len(foundDiagnostics) != 0 {
|
||||
diagnostics = append(diagnostics, foundDiagnostics...)
|
||||
continue
|
||||
policy := resolution.policy
|
||||
if incoming == nil || resolution.operation != sequenceModeReplace {
|
||||
var foundDiagnostics []Diagnostic
|
||||
policy, foundDiagnostics = collectionPolicyWithoutValue(lowerPointer, resolution.policy, retained, path)
|
||||
if len(foundDiagnostics) != 0 {
|
||||
diagnostics = append(diagnostics, foundDiagnostics...)
|
||||
continue
|
||||
}
|
||||
}
|
||||
if higher, ok := child.at(path); ok {
|
||||
policy = inheritanceRecordPoliciesFromHigher(policy, higher)
|
||||
|
||||
Reference in New Issue
Block a user