Skip to content

Element after if clause is rendered twice if function is used inside #1918

Open
@akesser

Description

@akesser

Bug Report

Resources that follow an if clause that evaluates to False are rendered twice, if a function is used inside of them

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

example in https://play.kcl-lang.io/?s=PoSwLgpgtgzgBAXjgbQLoCgBmBXAdgYzBAHtcAVCGMROAGwEMoAjAE3rgFoA+OKgJzgBvdHFFwARADd6tbBHHoAvulCRYcANRJkwsXFyMINcQEEFijCr7FaR7ZZCY4AMRkwIALhFjV0eFpRvPVFBAyg7CQAhcWU9SxVwP01tb10xMIgkcQBhBT0AawgATxocAiJSCioACgBKb2UHNXgkX1h0IA

_items = []
functionTest = lambda -> str {
    "value"
}
_items += [{
    name = "A"
}]

_role = []

if False:
    _items += [
        {name = "B"}
    ]


_items += [
  {
    name= "C"
    key = functionTest()
  }
]

items = _items

The code above creates the following output:

items:
- name: A
- name: C
  key: value
- name: C
  key: value

If the function call to functionTest() is removed the output is (as expected)

items:
- name: A
- name: C
  key: value

If the if clause resolves to True the output is (as expected)

items:
- name: A
- name: B
- name: C
  key: value

2. What did you expect to see? (Required)

Irrelevant of using a function in the last item, if the if evaluates to False, the output should be

items:
- name: A
- name: C
  key: value

3. What did you see instead (Required)

When using a function and if the if evaluates to False, the result is

items:
- name: A
- name: C
  key: value
- name: C
  key: value

4. What is your KCL components version? (Required)

0.11

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions