Skip to content

Struct upper bound #40

@cueckoo

Description

@cueckoo

Originally opened by @pblkt in cuelang/cue#40

The behavior of struct unification specified as

The successful unification of structs a and b is a new struct c which has all fields of both a and b

Cannot define an upper bound for structs. Specifically, CUE cannot help us verify that the resulting expression is limited to allowed fields.

For example, the unification

base: {
  onlyViableField: string | *"myDefault"
}

{
  base & {onlyViableFeild: "nonDefaultValue"}
}

yields

{
  onlyViableField: "myDefault"
  onlyViableFeild: "nonDefaultValue"
}

In kubernetes, the existence of extraneous fields causes failure when kubectl applys the resulting YAML, whereas in other systems the expression above could use silently use the default value erroneously.

When comparing CUE to a typed configuration language (like dhall), this is a qualitative difference in capabilities, since the extraneous field would be found by explicitly typing the result.

Extraneous fields can be hard to find - especially in large, opaque, auto-generated config schemes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions