From 1d4f4c7687bb605e915df48b837a20de6e62ccb3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 19 Apr 2022 18:29:08 +0200 Subject: [PATCH] cmd/cue/cmd: support byte in get go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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í Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536752 Unity-Result: CUEcueckoo Reviewed-by: Roger Peppe TryBot-Result: CUEcueckoo --- cmd/cue/cmd/get_go.go | 2 ++ cmd/cue/cmd/testdata/script/get_go_types.txt | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go index de66b053a3e..935ef0de7cb 100644 --- a/cmd/cue/cmd/get_go.go +++ b/cmd/cue/cmd/get_go.go @@ -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) } diff --git a/cmd/cue/cmd/testdata/script/get_go_types.txt b/cmd/cue/cmd/testdata/script/get_go_types.txt index 0e4ccbbc0c1..36dc2e6acd7 100644 --- a/cmd/cue/cmd/testdata/script/get_go_types.txt +++ b/cmd/cue/cmd/testdata/script/get_go_types.txt @@ -65,6 +65,8 @@ type Foozer struct { Ptr uintptr + Byte byte + // Time is mapped to CUE's internal type. Time time.Time @@ -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{} @@ -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 @@ -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: {