Skip to content

Unexpected behaviour when mutating variables in if-clauses #1910

Open
@RickardCardell

Description

@RickardCardell

Bug Report

Bug(s) related to variable-scopes and if-else clauses.
We discovered it when we had a composition that were supposed to create 3 resources but were creating 6.
The closest examples are example 5 and example 6 in the comments below.

1. Minimal reproduce step (Required)

Execute this KCL-code:

_counter = 0

if _counter == 0:
    _counter += 1
else:
    _counter += 1

assert _counter == 1, "Error: counter should be 1 but was ${_counter}"

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

_counter should be 1.

3. What did you see instead (Required)

Error: counter should be 1 but was 2

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

0.11.1

kcl version
0.11.1-darwin-arm64

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