cue icon indicating copy to clipboard operation
cue copied to clipboard

pkg/net: net.IP unification error

Open keeneh opened this issue 2 months ago • 2 comments

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

$ cue version
cue version v0.14.2

Does this issue reproduce with the latest stable release?

Yes

What did you do?

We have a process which automatically generates some constraints which results in something like:

--- x.cue ---
import "net"

{
	a: net.IP
	a: [...int]
}
cue eval x.cue

What did you expect to see?

import "net"

a: net.IP()

What did you see instead?

a: invalid value [] (does not satisfy net.IP):
    .\x.cue:4:5
    .\x.cue:5:5

keeneh avatar Oct 22 '25 00:10 keeneh

This is probably because [...int] defaults to the empty list, and so net.IP tries to validate that empty list.

Could you explain why are you trying to evaluate a regular and non-concrete field like this? Typically you would only define regular fields with concrete data. If you don't have data, then you should place your fields under a definition, for example for a schema.

mvdan avatar Oct 22 '25 09:10 mvdan

This is a simplificatoin of a larger set of constraints that we unify to create a larger schema. For example we would run this test code and expect no error.

func TestNetIpFillPath(t *testing.T) {
	cueCtx := cuecontext.New()

	cueVal1 := cueCtx.CompileString(`
		import "net"

		net.IP & [...int]
	`)

	cueVal2 := cueCtx.CompileString(`{}`)

	label := cue.Str("hello")
	path := cue.MakePath(label)
	cueVal3 := cueVal2.FillPath(path, cueVal1)

	err := cueVal3.Err()
	if err != nil {
		t.Error("expected no error but got " + err.Error())
	}
}

keeneh avatar Oct 22 '25 10:10 keeneh