Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KCL lambda arguments type checking in the language server #1527

Closed
dennybaa opened this issue Jul 30, 2024 · 9 comments
Closed

KCL lambda arguments type checking in the language server #1527

dennybaa opened this issue Jul 30, 2024 · 9 comments
Assignees
Labels
bug Something isn't working lsp resolver runtime Issues or PRs related to kcl runtime including value and value opertions semantic Issues or PRs related to kcl semantic and checker

Comments

@dennybaa
Copy link

dennybaa commented Jul 30, 2024

Hello, there

it looks like an odd behavior:

schema ProviderFamily:
    version: str
    providers: [str]
    marketplace: bool = True

providerFamily = lambda family: base.ProviderFamily {
    family
}
v = crossplane.providerFamily({
    version: "1.6.0"
    providers: [
        "provider-gcp-storage"
        "provider-gcp-compute"
    ]
    hello: "world"
})

I expect that the language server will be more informative regarding "hello", though it's not noticed, even CLI run provides meaningless error:

 kcl run appsops/iaas/crossplane/
EvaluationError
--> /home/dennybaa/code/play/pkg/apps/crossplane/base.k:1:1

Related scenario (which works, but should not)

schema Nested:
    m1?: str
    m2?: str

schema Top:
    inner: Nested

lambda a: Top {
}({
    inner: {hello: "world"}
})

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

0.9.4

@Peefy Peefy changed the title KCL lambda arguments type checking KCL lambda arguments type checking in the language server Jul 31, 2024
@Peefy Peefy added this to the v0.10.0 Release milestone Jul 31, 2024
@Peefy Peefy added bug Something isn't working semantic Issues or PRs related to kcl semantic and checker lsp labels Jul 31, 2024
@Peefy
Copy link
Contributor

Peefy commented Jul 31, 2024

@He1pa

Could you help fix it?

@dennybaa
Copy link
Author

Also it seems broader than this @Peefy , what do you think of an idea if arguments are passed to functions their copies are are constructed using the actual argument type? Does this sound sane or maybe nonsense?

@dennybaa
Copy link
Author

I guess impossible due to union TA | TB types...

@Peefy
Copy link
Contributor

Peefy commented Jul 31, 2024

No worries, I will refactor this and fix this issue.

@Peefy Peefy added the runtime Issues or PRs related to kcl runtime including value and value opertions label Aug 1, 2024
@dennybaa
Copy link
Author

dennybaa commented Aug 1, 2024

Hello there @Peefy, I'd like add more details, as I face runtime type checking failures, so it seems crucial.

Let's suppose we have a mutate function:

## vmgroups list
mutateGroups = lambda mutation: any, groups: [vm.OperatorVictoriametricsComV1beta1VMRuleSpecGroupsItems0] {
    [group | mutation for group in groups]
}

I define a vmrule:

vm.VMRule {
    metadata: base.metadata | {
        #name = config.app_id(item.resource_name())
        name = "xxxx"
        labels: {"team" = config.team, "app.kubernetes.io/name" = "rules"}
    }
  
    spec.groups: base.mutateGroups({labels.team = config.team}, [{
        name = "cert-manager"
        rules = [
            {
                alert = "cert-manager certificate expires soon"
                expr = "certmanager_certificate_expiration_timestamp_seconds - time() < 10 * 86400"
                $for = '5m'
                labels = {
                    severity = "critical"
                    service = "infra"
                }
                annotations = {
                    summary = "{{ $labels.cluster_name }}/{{ $labels.name }} expires in 10 days"
                }
            }
        ]
    }])
}

And get the runtime failure:

68 |         spec.groups: base.mutateGroups({labels.team = config.team}, [{
   |                                                ^ Cannot add member 'team' to schema 'OperatorVictoriametricsComV1beta1VMRuleSpecGroupsItems0'

However, I just need to move the groups assignment out and runtime is operational. In other words:

groups = base.mutateGroups(...)
vm.VMRule {
    metadata: base.metadata | {
        #name = config.app_id(item.resource_name())
        name = "xxxx"
        labels: {"team" = config.team, "app.kubernetes.io/name" = "rules"}
    }
    spec.groups: groups
}

This looks like kinda important error to me, smth is wrong with the type checking system and runtime.

@Peefy
Copy link
Contributor

Peefy commented Aug 1, 2024

Yes, I've fixed the type unsoundness at compile time and runtime through these PRs

@dennybaa
Copy link
Author

dennybaa commented Aug 1, 2024

Great, let's see then. Though unreleased yet?

@Peefy
Copy link
Contributor

Peefy commented Aug 1, 2024

Yes, I expect to release v0.10.0-alpha version.

@Peefy
Copy link
Contributor

Peefy commented Aug 20, 2024

Closed by #1531 and #1529, released in KCL v0.10.0-beta.1

@Peefy Peefy closed this as completed Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working lsp resolver runtime Issues or PRs related to kcl runtime including value and value opertions semantic Issues or PRs related to kcl semantic and checker
Projects
None yet
Development

No branches or pull requests

3 participants