Skip to content

Commit 37cc8ac

Browse files
mvdanmpvl
authored andcommitted
cmd/cue/cmd: support byte in get go
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í <mvdan@mvdan.cc> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/536752 Unity-Result: CUEcueckoo <cueckoo@cuelang.org> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
1 parent 5127136 commit 37cc8ac

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cmd/cue/cmd/get_go.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,6 +1132,8 @@ func (e *extractor) makeType(expr types.Type) (result cueast.Expr) {
11321132
switch t := x.String(); t {
11331133
case "uintptr":
11341134
return e.ident("uint64", false)
1135+
case "byte":
1136+
return e.ident("uint8", false)
11351137
default:
11361138
return e.ident(t, false)
11371139
}

cmd/cue/cmd/testdata/script/get_go_types.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ type Foozer struct {
6565

6666
Ptr uintptr
6767

68+
Byte byte
69+
6870
// Time is mapped to CUE's internal type.
6971
Time time.Time
7072

@@ -81,6 +83,7 @@ type Foozer struct {
8183
Array1 [5]int
8284
Array2 [5]interface{}
8385
Array3 *[5]json.Marshaler
86+
Array4 [5]byte
8487

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

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

0 commit comments

Comments
 (0)