kcl-lang / kcl

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

bug: when the full path of a symbolic link is used as the compile entry, the compilation fails #1660

Closed zong-zhe closed 1 month ago

zong-zhe commented 1 month ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

The use case:

$ tree
.
├── aaa
│   ├── kcl.mod
│   ├── kcl.mod.lock
│   └── sub
│       ├── sub.k
│       └── main.k
└── bbb
    ├── sub.k -> /Users/ccc/aaa/sub/sub.k
    ├── kcl.mod
    ├── kcl.mod.lock
    └── main.k -> /Users/ccc/aaa/sub/main.k

The sub.k

sub = 1

The main.k

import .sub as s

The_first_kcl_program = 'Hello World!'
b = s.sub

Compile main.k under bbb

$ cd bbb
$ kcl run main.k
error[E2F04]: CannotFindModule
 --> /Users/ccc/bbb/main.k:1:1
  |
1 | import .sub as s
  | ^ Cannot find the module .sub from //bbb/sub
  |

suggestion: try 'kcl mod add ' to download the missing package

suggestion: browse more packages at 'https://artifacthub.io'

error[E2G22]: TypeError
 --> /Users/ccc/bbb/main.k:4:5
  |
4 | b = s.sub
  |     ^ attribute 'sub' not found in 'module '..bbb.sub''
  |

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

The compile result

The_first_kcl_program: Hello World!
b: 1

3. What did you see instead (Required)

The error

error[E2F04]: CannotFindModule
 --> /Users/ccc/bbb/main.k:1:1
  |
1 | import .sub as s
  | ^ Cannot find the module .sub from //bbb/sub
  |

suggestion: try 'kcl mod add ' to download the missing package

suggestion: browse more packages at 'https://artifacthub.io'

error[E2G22]: TypeError
 --> /Users/ccc/bbb/main.k:4:5
  |
4 | b = s.sub
  |     ^ attribute 'sub' not found in 'module '..bbb.sub''
  |

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

The main branch of kpm, kcl and kcl cli.