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

cue: unification of open struct with a let expression fails #2325

Closed
errordeveloper opened this issue Apr 5, 2023 · 2 comments
Closed

cue: unification of open struct with a let expression fails #2325

errordeveloper opened this issue Apr 5, 2023 · 2 comments

Comments

@errordeveloper
Copy link

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

v0.5.0-rc.1

Does this issue reproduce with the latest stable release?

No.

What did you do?

exec go mod tidy
exec go run main.go
-- go.mod --
module m

go 1.19

require cuelang.org/go v0.5.0-rc.1
-- main.go --
package main

import (
	"fmt"

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

func main() {
	ctx := cuecontext.New()

	schema := ctx.CompileString(
		`package types
		 #T: {
			...
	    	 }`,
	).LookupPath(cue.ParsePath("#T"))

	data := ctx.CompileString(
		`package foo
	    	 let foobar = {}
	    	 _fb: foobar
	        `)

	fmt.Println(errors.Details(schema.Unify(data).Validate(), nil))
}

What did you expect to see?

No errors.

What did you see instead?

#T: field not allowed: foobar
@errordeveloper errordeveloper added NeedsInvestigation Triage Requires triage/attention labels Apr 5, 2023
@mvdan
Copy link
Member

mvdan commented Apr 5, 2023

A slightly shorter reproducer, which shows the success on v0.4.3 and failure on v0.5.0-rc.1:

exec go get cuelang.org/go@v0.4.3
exec go mod tidy
exec go run main.go
! stdout .

exec go get cuelang.org/go@v0.5.0-rc.1
exec go mod tidy
exec go run main.go
! stdout .

-- main.go --
package main

import (
	"fmt"

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

func main() {
	ctx := cuecontext.New()
	schema := ctx.CompileString(`
		#T: {}
	`).LookupPath(cue.MakePath(cue.Def("#T")))
	data := ctx.CompileString(`
		let foobar = {}
		_use: foobar
	`)
	fmt.Println(errors.Details(schema.Unify(data).Err(), nil))
}
-- go.mod --
module test

go 1.19
$ testscript -v -e GOMODCACHE=$(go env GOMODCACHE) repro-go.txtar 
> exec go get cuelang.org/go@v0.4.3
> exec go mod tidy
> exec go run main.go
[stdout]

> ! stdout .
> exec go get cuelang.org/go@v0.5.0-rc.1
> exec go mod tidy
> exec go run main.go
[stdout]
#T: field not allowed: foobar

> ! stdout .
FAIL: /tmp/testscript2657663051/repro-go.txtar/script.txtar:9: unexpected match for `.` found in stdout: #
error running repro-go.txtar in /tmp/testscript2657663051/repro-go.txtar

@mvdan
Copy link
Member

mvdan commented Apr 5, 2023

Unsurprisingly, this bisected to 36bd656, which is the CL I had already mentioned in the original discussion on Slack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants