Repository: kcl-lang/kcl (Rust)

Issue:
[Bug] The config entry identifier key is deduced as str type instead of string literal type
## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)

<!-- a step by step guide for reproducing the bug. -->

Write the following code (main.k) and run:

* main.k

```python
schema Id:
    id?: int

schema Config:
    data?: {"A"|"B":Id}

c = Config {
    data = {
        A = Id()
        B = Id()
    }
}
```

Run the cmd:

```cmd
kclvm_cli run main.k
```

### 2. What did you expect to see? (Required)

The YAML output

```yaml
c:
  data:
    A: {}
    B: {}
```

### 3. What did you see instead (Required)

```
KCL Compile Error[E2L23] : A complie error occurs during compiling
---> File main.k:8:4
8 |    data = {
    4 ^  -> Failure
expect {str(A)|str(B):Id}, got {str:Id}
```

### 4. What is your KusionStack components version? (Required)

<!-- Paste the output of Kusion/kclvm-go/KCLVM version -->

kclvm version is 0.4.4; checksum: c5339e572207211e46477825e8aca903

### 5. Supplement

+ The following code works normally ("A" instead of A and "B" instead of B)

```python3
schema Id:
    id?: int

schema Config:
    data?: {"A"|"B":Id}

c = Config {
    data = {
        "A" = Id()
        "B" = Id()
    }
}
```



Discussion:

Patch:
diff --git a/kclvm/sema/src/resolver/node.rs b/kclvm/sema/src/resolver/node.rs
index 4097db522..197b0d7ee 100644
--- a/kclvm/sema/src/resolver/node.rs
+++ b/kclvm/sema/src/resolver/node.rs
@@ -827,7 +827,7 @@ impl<'ctx> MutSelfTypedResultWalker<'ctx> for Resolver<'ctx> {
                             let key_ty = if self.ctx.local_vars.contains(name) {
                                 self.expr(key)
                             } else {
-                                self.str_ty()
+                                Rc::new(Type::str_lit(&name))
                             };
                             self.check_attr_ty(&key_ty, key.get_pos());
                             key_ty


Test patch:
diff --git a/kclvm/sema/src/resolver/tests.rs b/kclvm/sema/src/resolver/tests.rs
index e32e3eee3..9efe880f1 100644
--- a/kclvm/sema/src/resolver/tests.rs
+++ b/kclvm/sema/src/resolver/tests.rs
@@ -80,7 +80,10 @@ fn test_resolve_program_fail() {
     let diag = &scope.diagnostics[0];
     assert_eq!(diag.code, Some(DiagnosticId::Error(ErrorKind::TypeError)));
     assert_eq!(diag.messages.len(), 1);
-    assert_eq!(diag.messages[0].message, "expect int, got {str:int(1)}");
+    assert_eq!(
+        diag.messages[0].message,
+        "expect int, got {str(key):int(1)}"
+    );
 }
 
 #[test]
diff --git a/test/grammar/types/literal/lit_06_entry_id_key/main.k b/test/grammar/types/literal/lit_06_entry_id_key/main.k
new file mode 100644
index 000000000..37e43b9ba
--- /dev/null
+++ b/test/grammar/types/literal/lit_06_entry_id_key/main.k
@@ -0,0 +1,12 @@
+schema Id:
+    id?: int
+
+schema Config:
+    data?: {"A"|"B":Id}
+
+c = Config {
+    data = {
+        A = Id()
+        B = Id()
+    }
+}
diff --git a/test/grammar/types/literal/lit_06_entry_id_key/stdout.golden b/test/grammar/types/literal/lit_06_entry_id_key/stdout.golden
new file mode 100644
index 000000000..16f12c11c
--- /dev/null
+++ b/test/grammar/types/literal/lit_06_entry_id_key/stdout.golden
@@ -0,0 +1,4 @@
+c:
+  data:
+    A: {}
+    B: {}