kcl icon indicating copy to clipboard operation
kcl copied to clipboard

[Bug] Wrong References for the module variable

Open Peefy opened this issue 1 year ago • 6 comments

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

In the konfig repo https://github.com/kcl-lang/konfig/blob/main/models/kube/frontend/job.k

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

The right reference list

3. What did you see instead (Required)

image

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

v0.10.7

Peefy avatar Nov 04 '24 05:11 Peefy

Possibly this one is related too, running v0.10.7:

import .providers  # module
resources = {
    #                         v
    #                  module
    "providers": providers.installProviders  # [Provider]
    #                              v
    #                        [Provider]
    "vault-config": providers.vaultConfig # error
}
35 |     "vault-config": providers.vaultConfig
   |                     ^ attribute 'vaultConfig' not found in '[Provider]'

Actually resource.providers definition at top of resources uses a locally set providers. From one side it's kinda expected and what it should be, but it used to work before. Please share what the actual future behavior should be?

dennybaa avatar Nov 04 '24 21:11 dennybaa

Also, @Peefy please note that 0.10.7 behaves strange with modules, they appear exposed similarly to variables. However this one is unexpected, since the scope for import ... identifiers should be better file only, but not anymore...

  • sub/use_to_config.k (import ..config)
  • sub/main.k (import .config)
.
├── config.k
├── kcl.mod
├── kcl.mod.lock
├── main.k
└── sub
    ├── config.k
    ├── main.k
    └── use_top_config.k

This clashes with

   |
1 | import ..config
  | ^ the name 'config' is defined multiple times, 'config' must be defined only once

dennybaa avatar Nov 04 '24 21:11 dennybaa

Yes, some recent bug fixes have caused these regression errors. We will fix it later and release it in v0.10.8+ and v0.11.x

Peefy avatar Nov 05 '24 02:11 Peefy

Hello, @Peefy I'd like to kindly ask about any plans for this? Also what bothers me a bit, is an unclear migration path from from 0.9.8 to 0.11.x.

  1. First this issue which messes up variables with imports.
  2. Second is the ordered file load behavior. Let's say in b.kcl file has var = true and in main.kcl there is output = var this works fine on 0.9.x. And in 0.11 seemed like the order is broken (or it could be actually I couldn't just say for sure becouse of broken imports), or maybe it tries to behave like cue the file order doesn't matter.

Please could clarify this, since the scope for issues seems quite broad to me. So what the load behavior for KCL should actually be from now on?

Thank you!

dennybaa avatar Jan 21 '25 14:01 dennybaa

I want to confirm, does the problem you mentioned only occur in the IDE, or does it occur in the IDE and during the compilation process? Regarding the module-related behaves, there are some updates in the IDE. But I don't think this should affect the normal compilation process.

Regarding file dependencies and loading order, for entry files, they are in order, for example, kcl run a.k b.k or entries in kcl.mod, there is an order between a and b. For dependent files, such as import c in a.k. The correct order should be c a b

He1pa avatar Jan 22 '25 02:01 He1pa

@He1pa yep, this unfortunately not the language sever issue only. It's compilation issue too. Thanks, though I referred to load order inside a directory, when you invoke dir/main.k which in turn might implicitly access vars from dir/a.k. Does this behavior persist in the new versions?

this comment describes compilation issue: https://github.com/kcl-lang/kcl/issues/1734#issuecomment-2455751382

dennybaa avatar Jan 22 '25 09:01 dennybaa