Skip to content

Commit 112b0b2

Browse files
uhthomasmvdan
authored andcommitted
cmd/cue: ignore complex types in get go
Complex numbers have no opaque representation in Go. The real and imaginary parts of a complex number are only accessible using the inbuilt functions real and imag. There is also no agreed upon standard for representing complex numbers in other data formats like JSON or YAML. Most encoders will simply write strings in the form "1+2i". I think the safest thing to do for now is to represent complex numbers with top, and adjust this in future if needed. Fixes #2661 Change-Id: Ibdcbf04a535490a4936323b37c79eec12bbd822c Signed-off-by: Thomas Way <[email protected]> Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1170115 Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Daniel Martí <[email protected]> TryBot-Result: CUEcueckoo <[email protected]>
1 parent 8b32c49 commit 112b0b2

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

cmd/cue/cmd/get_go.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1187,9 +1187,10 @@ func (e *extractor) makeType(expr types.Type) (result cueast.Expr) {
11871187
return e.ident("uint64", false)
11881188
case types.Byte:
11891189
return e.ident("uint8", false)
1190-
default:
1191-
return e.ident(x.String(), false)
1190+
case types.Complex64, types.Complex128:
1191+
return e.ident("_", false)
11921192
}
1193+
return e.ident(x.String(), false)
11931194

11941195
case *types.Union:
11951196
var exprs []cueast.Expr

cmd/cue/cmd/testdata/script/get_go_types.txtar

+17-8
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"encoding"
4545
"encoding/json"
4646
"time"
47+
"unsafe"
4748

4849
p2 "mod.test/pkg2"
4950
)
@@ -67,6 +68,11 @@ type Foozer struct {
6768

6869
Ptr uintptr
6970

71+
UnsafePointer unsafe.Pointer
72+
73+
Complex64 complex64
74+
Complex128 complex128
75+
7076
Byte byte
7177

7278
// Time is mapped to CUE's internal type.
@@ -248,14 +254,17 @@ import (
248254
String: string
249255

250256
#Inline
251-
NoInline: #NoInline
252-
CustomJSON: #CustomJSON
253-
CustomYAML?: null | #CustomYAML @go(,*CustomYAML)
254-
AnyJSON: _ @go(,json.Marshaler)
255-
AnyText: string @go(,encoding.TextMarshaler)
256-
bar?: int & >10 @go(Bar)
257-
Ptr: uint64 @go(,uintptr)
258-
Byte: uint8 @go(,byte)
257+
NoInline: #NoInline
258+
CustomJSON: #CustomJSON
259+
CustomYAML?: null | #CustomYAML @go(,*CustomYAML)
260+
AnyJSON: _ @go(,json.Marshaler)
261+
AnyText: string @go(,encoding.TextMarshaler)
262+
bar?: int & >10 @go(Bar)
263+
Ptr: uint64 @go(,uintptr)
264+
UnsafePointer: uint64 @go(,unsafe.Pointer)
265+
Complex64: _ @go(,complex64)
266+
Complex128: _ @go(,complex128)
267+
Byte: uint8 @go(,byte)
259268

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

0 commit comments

Comments
 (0)