Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/vrl/compiler/src/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,22 @@ impl TypeDef {
}

pub fn merge(&mut self, other: Self, strategy: merge::Strategy) {
self.kind.merge(other.kind, strategy);
self.fallible |= other.fallible;

// NOTE: technically we shouldn't do this, but to keep backward compatibility with the
// "old" `Kind` implementation, we consider a type that is marked as "any" equal to the old
// implementation's `unknown`, which, when merging, would discard that type.
//
// see: https://github.com/vectordotdev/vector/blob/18415050b60b08197e8135b7659390256995e844/lib/vrl/compiler/src/type_def.rs#L428-L429
Comment on lines +354 to +358
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me which "right" way you envision here or does this comment not imply that we should change any of this logic in the future?

If we intend to change it, I'd suggest opening an issue with the proposed logic and a migration plan.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll likely introduce a new merge Strategy option that allows ignoring any values. It's not "bad" per sé, but it is confusing behaviour without explicitly requesting it as the caller of a type definition merge.

For now, that strategy doesn't exist in the value crate, so it lives here in VRL, I'll think on what the best next steps would be to either remove the need for this entirely, or move it to a more "official" place as a strategy in the value crate.

if !self.is_any() && other.is_any() {
// keep `self`'s `kind` definition
} else if self.is_any() && !other.is_any() {
// overwrite `self`'s `kind` definition with `others`'s
self.kind = other.kind;
} else {
// merge the two `kind`s
self.kind.merge(other.kind, strategy);
}
}

pub fn merge_overwrite(mut self, other: Self) -> Self {
Expand Down
13 changes: 13 additions & 0 deletions lib/vrl/tests/tests/issues/11287_http_pipelines_blackhole.vrl
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# issue: https://github.com/vectordotdev/vector/pull/11287
# result: [["bar"], ["qux"], { "bar": true }]

.a1, err = push(.a1, "foo")
.a1 = push(.a1, "bar")

.a2, err = append(.a2, ["baz"])
.a2 = append(.a2, ["qux"])

.a3, err = merge(.a3, { "foo": true })
.a3 = merge(.a3, { "bar": true })

[.a1, .a2, .a3]