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

Using a mutable variable with if-elif in mixin results in unsetting the variable #1835

Open
Freewalkr opened this issue Jan 21, 2025 · 0 comments
Milestone

Comments

@Freewalkr
Copy link

Freewalkr commented Jan 21, 2025

Bug Report

1. Minimal reproduce step (Required)

mixin NoCondMixin:
    _a: [str] = []
    _a += ["text1"]
    _a += ["text2"]

mixin OneCondMixin:
    _a: [str] = []
    _a += ["text1"]
    if mod == "m":
        _a += ["text2"]

mixin TwoCondMixin:
    _a: [str] = []
    _a += ["text1"]
    if mod == "m":
        _a += ["text2"]
    elif mod == "n":
        _a += ["text3"]

schema NoCondSchema:
    mixin [NoCondMixin]
    mod: str
    a: [str] = _a or ["dummy"]

schema OneCondSchema:
    mixin [OneCondMixin]
    mod: str
    a: [str] = _a or ["dummy"]

schema TwoCondSchema:
    mixin [TwoCondMixin]
    mod: str
    a: [str] = _a or ["dummy"]

ncs = NoCondSchema { mod = "m" }
ocs = OneCondSchema { mod = "m" }
tcs = TwoCondSchema { mod = "m" }

Interesting that if I don't add or ["dummy"] in TwoCondSchema, KCL throws attribute 'a' of TwoCondSchema is required and can't be None or Undefined error.

Also if I merge mixins' contents into schemas, everything works as expected.

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

ncs:
  mod: m
  a:
  - text1
  - text2
ocs:
  mod: m
  a:
  - text1
  - text2
tcs:
  mod: m
  a:
  - text1
  - text2

3. What did you see instead (Required)

ncs:
  mod: m
  a:
  - text1
  - text2
ocs:
  mod: m
  a:
  - text1
  - text2
tcs:
  mod: m
  a:
  - dummy

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

KCL v0.11.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants