kcl-lang / kcl

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

The implicit type specification issue (KCL_FAST_EVAL=1) #1417

Closed bozaro closed 1 week ago

bozaro commented 2 weeks ago

Bug Report

1. Minimal reproduce step (Required)

Run shell script:

#!/bin/sh -e

# Use temporary directory
cd $(mktemp -d)

# Create kcl.mod
cat > kcl.mod << EOF
[package]
name = "kcl-fast-eval"
edition = "0.0.1"
version = "0.0.1"
EOF

# Create types/host.k
mkdir -p types && cat > types/host.k << EOF
schema Host:
    host: str

schema HostPort(Host):
    port: int
EOF

# Create example/main.k
mkdir -p example && cat > example/main.k << EOF
import types

hosts: {str:types.HostPort} = {
    foo: {host: "foo.example.net", port: 80}
    bar: {host: "bar.example.net", port: 80}
}
EOF

# Show executed commands
set -x

# Show version
kcl version

# Run without KCL_FAST_EVAL
kcl run example/

# Run with KCL_FAST_EVAL
KCL_FAST_EVAL=1 kcl run example/

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

kcl run example/ and KCL_FAST_EVAL=1 kcl run example/ got same output like:

hosts:
  foo:
    host: foo.example.net
    port: 80
  bar:
    host: bar.example.net
    port: 80

3. What did you see instead (Required)

+ kcl run example/
hosts:
  foo:
    host: foo.example.net
    port: 80
  bar:
    host: bar.example.net
    port: 80
+ KCL_FAST_EVAL=1 kcl run example/
failed to compile the kcl package
EvaluationError
 --> /tmp/tmp.2Z2j6pbIo0/example/main.k:5:1
  |
5 |     bar: {host: "bar.example.net", port: 80}
  |  expect {str:types.HostPort}, got dict
  |

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

+ kcl version
0.9.0-beta.1-linux-amd64
bozaro commented 2 weeks ago

Also this issue is reproducable with kclvm_cli executable built from actual main branch code (https://github.com/kcl-lang/kcl/commit/dadfd041bfee13a9e461bf40b44f387947d0de1a):

[10:19:38] ➜  script /home/bozaro/github/kcl/_build/dist/ubuntu/kclvm/bin/kclvm_cli version
Version: 0.9.0-0c20ab3eb4b9179219d6837a57f5d352
Platform: x86_64-unknown-linux-gnu
GitCommit: dadfd041bfee13a9e461bf40b44f387947d0de1a

[10:19:52] ➜  script KCL_FAST_EVAL=1 /home/bozaro/github/kcl/_build/dist/ubuntu/kclvm/bin/kclvm_cli run example
error[E3M38]: EvaluationError
 --> /home/bozaro/xxx/kcl-fast-eval/script/example/main.k:5:1
  |
5 |     bar: {host: "bar.example.net", port: 80}
  |  expect {str:types.HostPort}, got dict
  |