Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for_each doesn't affect type #850

Open
Rajin9601 opened this issue May 21, 2024 · 1 comment
Open

for_each doesn't affect type #850

Rajin9601 opened this issue May 21, 2024 · 1 comment
Labels
type: bug A code related bug vrl: compiler Changes to the compiler

Comments

@Rajin9601
Copy link

body = del(.)
for_each(["test1"]) -> |key, path| {
  ., err = set(., ["new", path], "test1")
}
.new.test2 = "test2"

this VRL program fails in compiling because of type of .new. (VRL Playground Link)

Error Log

error[E642]: parent path segment rejects this mutation
  ┌─ :5:6
  │
5 │ .new.test2 = "test2"
  │ ---- ^^^^^ querying a field of a non-object type is unsupported
  │ │
  │ this path resolves to a value of type undefined
  │
  = try: change parent value to object, before assignment
  =
  =     .new = {}
  =     .new.test2 = "test2"
  =
  = see documentation about error handling at https://errors.vrl.dev/#handling
  = see language documentation at https://vrl.dev
  = try your code in the VRL REPL, learn more at https://vrl.dev/examples

However, if it's inside an if statement instead of for_each, this vrl program can be compiled.

body = del(.)
if is_boolean(body.message) {
    ., err = set(., ["new", "test1"], "test1")
}
.new.test2 = "test2"

VRL Playground link

My theory is that .'s type is not changed by the for_each statement, which looks like a bug.

@jszwedko
Copy link
Member

Aha, interesting, thanks for this report @Rajin9601 . That does look like a type definition bug to me.

@jszwedko jszwedko added type: bug A code related bug vrl: compiler Changes to the compiler labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A code related bug vrl: compiler Changes to the compiler
Projects
None yet
Development

No branches or pull requests

2 participants