Skip to content

cue: struct.MinFields causes inappropriate error #3867

Open
@rogpeppe

Description

@rogpeppe

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

$ cue version
72567b93ca6309a865fd45a3ffe14f9957134a25

Does this issue reproduce with the latest stable release?

v0.13.0-alpha.3

What did you do?

exec go mod tidy
exec go run .
cmp stdout want-stdout

-- want-stdout --
struct
<nil>
-- go.mod --
module tstcue

go 1.23.0

require (
	cuelang.org/go v0.13.0-alpha.3
	github.com/go-quicktest/qt v1.101.0
)

-- main.go --
package main

import (
	"fmt"

	"cuelang.org/go/cue/cuecontext"
)

func main() {
	ctx := cuecontext.New()
	v := ctx.CompileString(`
import "struct"
{x?: bool} & struct.MinFields(1)
`)
	fmt.Println(v.IncompleteKind())
	fmt.Println(v.Err())
}

What did you expect to see?

A passing test. Adding a MinFields constraint that may be satisfied later should not cause IncompleteKind to return bottom.

This behaviour means it's not possible to inspect such incomplete values to see what kind they might be, which hinders tooling.

What did you see instead?

> exec go mod tidy
> exec go run .
[stdout]
_|_
invalid value {x?:bool} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1)
> cmp stdout want-stdout
diff stdout want-stdout
--- stdout
+++ want-stdout
@@ -1,2 +1,2 @@
-_|_
-invalid value {x?:bool} (does not satisfy struct.MinFields(1)): len(fields) < MinFields(1) (0 < 1)
+struct
+<nil>

FAIL: /tmp/x.txtar:4: stdout and want-stdout differ

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions