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

[Bug] Invalid schema string attribute contains dot #1227

Closed Peefy closed 5 months ago

Peefy commented 5 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

schema Name:
    "a.b": str = "1"

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

Compile sucessful!

kcl main.k

3. What did you see instead (Required)

error[E2L23]: CompileError
 --> main.k:2:5
  |
2 |     "a.b": str = "1"
  |     ^ schema attribute can not be selected
  |

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

kcl v0.8.4

metacoma commented 5 months ago

here is a "real-world" usage example

schema ArgoCdManifest:
    [str]: any
    metadata: ArgoCdManifestMetadata

schema ArgoCdManifestMetadata:
    [str]: any
    annotations: ArgoCdManifestMetadataAnnotations

schema ArgoCdManifestMetadataAnnotations:
    [str]: any
    "argocd.argoproj.io/sync-wave": str
    "argocd.argoproj.io/phase": str
    check:
        argocd.argoproj.io/phase in ["preSync","sync","postSync"]
        int(argocd.argoproj.io/sync-wave) >= 1

preparePhase = lambda phase: str, a: [any] -> [ArgoCdManifest] {
    resources = filter resource in a {
        resource != None
    }
    sync_wave = 0
    [

        resource | ArgoCdManifest { 
            metadata = {
                annotations = {
                    "argocd.argoproj.io/sync-wave"" = phase
                    "argocd.argoproj.io/phase" = str(sync_wave + 1)
                }
            }
        }
        for resource in resources 
    ] 
}