kcl-lang / kcl

KCL Programming Language (CNCF Sandbox Project). https://kcl-lang.io
https://kcl-lang.io
Apache License 2.0
1.61k stars 112 forks source link

Some objects are stored in memory of KCL daemon and are not cleaned up #1205

Closed vtomilov closed 5 months ago

vtomilov commented 5 months ago

Bug Report

I was playing around the KCL playground and found some inconsistent behavior. So each time I run my script I get different results, thats a very much unexpected behavior. This bug reproduces in your playground (just run it multiple times) http://101.42.3.224/-/play/index.html?id=4a07ca5a47983a5eca6541d36a144785eb5e4db6

1. Minimal reproduce step (Required)

a = {
    "foo": 1,
    "bar": 2,
}

_r = 0

inc = lambda v {
    _r += 1
    v 
}

_t = {k:inc(v) for k,v in a}

r = _r

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

a:
  foo: 1
  bar: 2
r: 2

3. What did you see instead (Required)

a:
  foo: 1
  bar: 2
r: 10

And r: 10 increases by 2 every time I hit the run button or change some code.

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

0.8.0, 0.7.0

Peefy commented 5 months ago

Hello @vtomilov Thank you for your feedback. This unexpected situation only occurs when the number 0 and function closure are captured. I opened a PR to fix it https://github.com/kcl-lang/kcl/pull/1206