cuelang / cue

CUE has moved to https://github.com/cue-lang/cue
https://cuelang.org
Apache License 2.0
3.09k stars 171 forks source link

Question about Value.IsConcrete()? #883

Closed verdverm closed 3 years ago

verdverm commented 3 years ago

What version of CUE are you using (cue version)?

0.3.0

What did you do?

Called cue.Value.IsConcrete() via the Go API and got unexpected results. If this does indeed seem like a bug, then I can create a reproducer.

In the example below, calling IsConcrete() for ex.bar. reports true, is this expected?

#A: {
  a1: string
  a2: string | *""
}

#B: {
  foo: string
  bar: #A
}

ex: #B & {
  foo: "foo"
}

What did you expect to see?

ex.bar.IsConcrete() returning false

What did you see instead?

ex.bar.IsConcrete() returning true

myitcv commented 3 years ago

AFAIU, this is working "as expected" but is effectively the same problem of a list type defaulting to [], picked up in the required fields proposal. i.e. the default value of #A here is {}. What I think you are looking to distinguish is whether ex.bar is specified or not, and that is where the ! proposal comes in.

mpvl commented 3 years ago

It is working as expected because, as documented, a struct is always considered concrete.

As per the doc:

It does not verify that values of lists or structs are concrete themselves.