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

bug: inconsistently-shaped instances from Translate and Validate #155

Closed
mildwonkey opened this issue May 17, 2023 · 1 comment · Fixed by #157
Closed

bug: inconsistently-shaped instances from Translate and Validate #155

mildwonkey opened this issue May 17, 2023 · 1 comment · Fixed by #157

Comments

@mildwonkey
Copy link

This is very hard to describe in prose, so here's an example!
https://github.com/mildwonkey/thema-examples/tree/main/translate

Here's the incredibly simplified, pseudocode tl;dr:

i0, _ := sch.Validate(exdata)
title, _ := i0.Underlying().LookupPath(cue.ParsePath("title")).String()
fmt.Println(title) // "foo"

i1, _ := i0.Translate(thema.SV(0, 1))
title1, err := i1.Underlying().LookupPath(cue.ParsePath("title")).String()
fmt.Println(err) // #Translate.out.result.result: field not found: title

The title field is unchanged and should be accessible with the same Underlying().LookupPath method.

@sdboyer
Copy link
Contributor

sdboyer commented May 17, 2023

Thanks for the issue!

A little more from debugging, we see this output along these lines when calling fmt.Fprintf("%#v") on the cue.Value returned from cue.Value returned from Instance.Underlying():

_#def
_#def: *{
	_accum[i].result
	schdef._#schema
} | INST.#x

//cue:path: #Translate.inst
let INST = {
	#x: {
		title: "foo", ...
	}
}

It looks like our current tests for translate (both vmux tests and this txtar) didn't catch this because they look only at what happens when the cue.Value here is exported/forced to concreteness, so that it can be encoded as JSON or into a Go struct or whatever. That causes all of these internals to collapse to the expected concrete value, resulting in passing tests.

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

Successfully merging a pull request may close this issue.

2 participants