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

cmd/cue: get go generates invalid CUE from byte type #1336

Closed
james-maloney opened this issue Oct 26, 2021 · 2 comments
Closed

cmd/cue: get go generates invalid CUE from byte type #1336

james-maloney opened this issue Oct 26, 2021 · 2 comments
Assignees
Labels
get go issues related to cue get go NeedsFix

Comments

@james-maloney
Copy link

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

$ cue version
cue version v0.4.0 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

package cuego

import "github.com/google/uuid"

type Bar struct {
    ID uuid.UUID
}

Generate Cue from Go package

cue get go cuego

Output:

$cat cuego/types_go_gen.cue

// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go cuego

package cuego

import "github.com/google/uuid"

#Bar: ID: uuid.#UUID

Vet

cue vet gen/cuego/types_go_gen.cue
#Domain: reference "byte" not found:
    ./gen/github.com/google/uuid/dce_go_gen.cue:8:10
#Version: reference "byte" not found:
    ./gen/github.com/google/uuid/uuid_go_gen.cue:12:11
#Variant: reference "byte" not found:
    ./gen/github.com/google/uuid/uuid_go_gen.cue:15:11

What did you expect to see?

A valid cue file generated from the Go package

What did you see instead?

An invalid cue file using an un-known byte type

// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go github.com/google/uuid

package uuid

// A Domain represents a Version 2 domain
#Domain: byte // #enumDomain

#enumDomain:
	#Person |
	#Group |
	#Org

#values_Domain: {
	Person: #Person
	Group:  #Group
	Org:    #Org
}

#Person: #Domain & 0
#Group:  #Domain & 1
#Org:      #Domain & 2
@james-maloney james-maloney added NeedsInvestigation Triage Requires triage/attention labels Oct 26, 2021
@slewiskelly
Copy link
Contributor

slewiskelly commented Oct 26, 2021

In Go, but not in CUE, a byte is an alias for uint8.

Using uint8 in place of byte works as expected, so (naively) assume a similar translation needs to occur?

The only documentation I see about byte or bytes is when translating arrays or slices:

  • slices and arrays convert to CUE lists, except when the element type is byte, in which case it translates to the CUE bytes type.

However, there is a note here which mentions why there is no byte builtin:

Do not include an alias for "byte", as it would be too easily confused with the builtin "bytes".

@myitcv myitcv changed the title Cue generates invalid Cue from Go's byte type cmd/cue: get go generates invalid CUE from byte type Oct 29, 2021
@myitcv myitcv added get go issues related to cue get go NeedsFix and removed NeedsInvestigation Triage Requires triage/attention labels Oct 29, 2021
@myitcv
Copy link
Member

myitcv commented Oct 29, 2021

Thanks for the report, @james-maloney.

Confirmed with e8550b8:

exec cue get go --local .
exec cue eval

-- go.mod --
module mod.com

go 1.16
-- main.go --
package cuego

type Bar byte
-- main_go_gen.cue --
// Code generated by cue get go. DO NOT EDIT.

//cue:generate cue get go mod.com

package cuego

#Bar: byte

gives:

> exec cue eval
[stderr]
#Bar: reference "byte" not found:
    ./main_go_gen.cue:7:7
[exit status 1]
FAIL: /tmp/testscript009373651/repro.txt/script.txt:2: unexpected command failure

@mvdan mvdan self-assigned this Apr 12, 2022
cueckoo pushed a commit that referenced this issue Apr 19, 2022
Much like the last change to teach it about uintptr,
do the same about byte, an alias for uint8 in Go.

Note that the get_go code already had special cases to handle byte
slices and arrays, but byte arrays had no test coverage here,
so we add a test case for them as well.

Fixes #1336.

Change-Id: I040b12da56077cee60e699aa31d1ebcd78e6bc28
Signed-off-by: Daniel Martí <[email protected]>
qequ pushed a commit to qequ/cue that referenced this issue May 20, 2022
Much like the last change to teach it about uintptr,
do the same about byte, an alias for uint8 in Go.

Note that the get_go code already had special cases to handle byte
slices and arrays, but byte arrays had no test coverage here,
so we add a test case for them as well.

Fixes cue-lang#1336.

Change-Id: I040b12da56077cee60e699aa31d1ebcd78e6bc28
Signed-off-by: Daniel Martí <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536752
Unity-Result: CUEcueckoo <[email protected]>
Reviewed-by: Roger Peppe <[email protected]>
TryBot-Result: CUEcueckoo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
get go issues related to cue get go NeedsFix
Projects
None yet
Development

No branches or pull requests

4 participants