Skip to content

Commit

Permalink
cmd/cue/cmd: support byte in get go
Browse files Browse the repository at this point in the history
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]>
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]>
  • Loading branch information
mvdan authored and mpvl committed Apr 20, 2022
1 parent 5127136 commit 37cc8ac
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/cue/cmd/get_go.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,8 @@ func (e *extractor) makeType(expr types.Type) (result cueast.Expr) {
switch t := x.String(); t {
case "uintptr":
return e.ident("uint64", false)
case "byte":
return e.ident("uint8", false)
default:
return e.ident(t, false)
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/cue/cmd/testdata/script/get_go_types.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ type Foozer struct {

Ptr uintptr

Byte byte

// Time is mapped to CUE's internal type.
Time time.Time

Expand All @@ -81,6 +83,7 @@ type Foozer struct {
Array1 [5]int
Array2 [5]interface{}
Array3 *[5]json.Marshaler
Array4 [5]byte

Intf Interface `protobuf:"varint,2,name=intf"`
Intf2 interface{}
Expand Down Expand Up @@ -397,6 +400,7 @@ import (
AnyText: string @go(,encoding.TextMarshaler)
bar?: int & >10 @go(Bar)
Ptr: uint64 @go(,uintptr)
Byte: uint8 @go(,byte)

// Time is mapped to CUE's internal type.
Time: time.Time
Expand All @@ -412,6 +416,7 @@ import (
Array1: 5 * [int] @go(,[5]int)
Array2: 5 * [_] @go(,[5]interface{})
Array3?: null | 5*[_] @go(,*[5]json.Marshaler)
Array4: bytes @go(,[5]byte)
Intf: #Interface @protobuf(2,varint,name=intf)
Intf2: _ @go(,interface{})
Intf3: {
Expand Down

0 comments on commit 37cc8ac

Please sign in to comment.