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/def: running def on the output creates increasingly nested results #2251

Closed
verdverm opened this issue Feb 7, 2023 · 3 comments
Closed
Assignees
Labels

Comments

@verdverm
Copy link

verdverm commented Feb 7, 2023

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

$ cue version
cue version v0.5.0-beta.5

go version go1.19.3
       -compiler gc
       -trimpath true
     CGO_ENABLED 0
          GOARCH amd64
            GOOS linux
         GOAMD64 v1

What did you do?

exec cue def 1.cue --outfile 2.cue
exec cue def 2.cue --outfile 3.cue
exec cue def 3.cue
cmp 3.cue golden.output

-- 1.cue --
package main

import "hof.io/repro/foo"

foo.#Foo

a: "A"

-- foo/foo.cue --
package foo

#Foo: {
	a: string
}

-- cue.mod/module.cue --
module: "hof.io/repro"

-- golden.output --
package main

import "hof.io/repro/foo"

foo.#Foo
a: "A"

What did you expect to see?

the final output is the same as the original

What did you see instead?

package main

import "hof.io/repro/foo"

_#def
_#def: {
        _#def
        foo.#Foo
        foo.#Foo
        _#def: {
                _#def
                _#def: {
                        foo.#Foo
                        a: "A"
                }
        }
        a: "A"
}
@verdverm verdverm added NeedsInvestigation Triage Requires triage/attention labels Feb 7, 2023
@mvdan
Copy link
Member

mvdan commented Feb 7, 2023

Does this happen with v0.4.3? That's what the section about "latest release" in the bug template is for.

@verdverm
Copy link
Author

verdverm commented Feb 7, 2023

With v0.4.3

package main

import "hof.io/repro/foo"

_#def
_#def: {
        _#def
        _#def: {
                _#def
                _#def: {
                        foo.#Foo
                        a: "A"
                }
        }
}

While cleaner, I would still consider this undesirable output

@myitcv myitcv added zGarden and removed zGarden labels Jun 13, 2023
@myitcv
Copy link
Member

myitcv commented Jun 14, 2023

@verdverm - just to confirm, is the intent behind embedding foo.#Foo into package main, to enforce that package main should then satisfy foo.#Foo?

If so, this gets close to needing what we want in #575 (or similar): a mechanism by which we can enforce that a package value satisfies a given schema. Because the problem with embedding (as in this case) is that closedness is relaxed during the embedding... which is almost certainly not what was intended.

The current behaviour of def is to apply some sort of heuristic that guesses what the user was trying to do. If we implement something like must() (bike shedding on name and semantics) that heuristic can go away entirely.

@myitcv myitcv added this to the v0.6.0 required fields milestone Jun 14, 2023
@myitcv myitcv added NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Jun 14, 2023
@mpvl mpvl self-assigned this Jul 3, 2023
cueckoo pushed a commit that referenced this issue Jul 4, 2023
Will be fixed in a later CL.

Issue #2251

Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com>
Change-Id: Icdb00a29e3023b00083de0550da127632a77e7dd
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/556346
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo+gerrithub@cuelang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
@cueckoo cueckoo closed this as completed in d112f64 Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants