@@ -188,10 +188,10 @@ fail.both."42_LinkedList".types.LinkedList.next: conflicting values "x" and {ite
188
188
./root/types.cue:43:14
189
189
fail.both.notList: conflicting values [1,2,3] and {embedded2?:int} (mismatched types list and struct):
190
190
./cuetest/all.cue:5:24
191
- ./root/root.cue:127 :2
191
+ ./root/root.cue:136 :2
192
192
fail.both.notString: conflicting values "not_a_struct" and {embedded2?:int} (mismatched types string and struct):
193
193
./cuetest/all.cue:4:24
194
- ./root/root.cue:127 :2
194
+ ./root/root.cue:136 :2
195
195
fail.cue."11_Int8".types.Int8: invalid value 99999 (out of bound <=127):
196
196
./cuetest/all.cue:61:30
197
197
fail.cue."12_Int8".types.Int8: invalid value -99999 (out of bound >=-128):
@@ -251,6 +251,7 @@ import (
251
251
"slices"
252
252
253
253
"foo.test/bar/root"
254
+ imported "foo.test/bar/imported/subinst"
254
255
)
255
256
256
257
type Tests struct {
@@ -267,8 +268,9 @@ func main() {
267
268
var _ root.AttrChangedNameEmbed
268
269
var _ = root.AttrType(constant.Kind(0))
269
270
270
- // It's easier to test the fields with a root value .
271
+ // It's easier to test the fields with zero values .
271
272
var zeroRoot root.Root
273
+ var zeroRootImports root.RootImports
272
274
273
275
var _ = zeroRoot.Embedded1
274
276
var _ = zeroRoot.Embedded2
@@ -282,12 +284,27 @@ func main() {
282
284
zeroRoot.DiscriminatorField = make(map[string]any)
283
285
284
286
// Optional fields which use the optional attribute flag.
287
+
285
288
zeroRoot.Fields.OptionalBasic = 5
286
289
zeroRoot.Fields.OptionalList = make([]int64, 0)
287
290
zeroRoot.Fields.OptionalMap = make(map[string]int64, 0)
288
- zeroRoot.Fields.OptionalBasicAttrNillable = new(int64)
289
- zeroRoot.Fields.OptionalListAttrNillable = new([]int64)
290
- zeroRoot.Fields.OptionalMapAttrNillable = new(map[string]int64)
291
+
292
+ zeroRoot.Fields.OptionalTopAttrNillable = (*any)(nil)
293
+ zeroRoot.Fields.OptionalNullAttrNillable = (**struct{})(nil)
294
+ zeroRoot.Fields.OptionalBasicAttrNillable = (*int64)(nil)
295
+ zeroRoot.Fields.OptionalListAttrNillable = (*[]int64)(nil)
296
+
297
+ zeroRoot.Fields.OptionalInlineMapAttrNillable = (*map[string]int64)(nil)
298
+ zeroRoot.Fields.OptionalLocalMapAttrNillable = (*root.LocalMap)(nil)
299
+ zeroRoot.Fields.OptionalInlineNestedAttrNillable = (*struct{F *[]string `json:"f,omitempty"`})(nil)
300
+ zeroRoot.Fields.OptionalLocalNestedAttrNillable = (*root.LocalNested)(nil)
301
+
302
+ // #localNested is not affected by one of the references using optional=nullable.
303
+ var _ = root.LocalNested{F: []string{}}
304
+
305
+ zeroRootImports.OptionalRemoteMapAttrNillable = (*imported.RemoteMap)(nil)
306
+ zeroRootImports.OptionalRemoteNestedAttrNillable = (*imported.RemoteNested)(nil)
307
+
291
308
zeroRoot.Fields.OptionalStruct = root.EmptyStruct{}
292
309
zeroRoot.Fields.OptionalStructAttrType = root.EmptyStruct{}
293
310
zeroRoot.Fields.OptionalStructAttrZero = root.EmptyStruct{}
@@ -389,9 +406,18 @@ _#overridenNeverGenerate: string
389
406
optionalList?: [...int]
390
407
optionalMap?: [string]: int
391
408
409
+ optionalTopAttrNillable?: _ @go(,optional=nillable)
410
+ optionalNullAttrNillable?: null @go(,optional=nillable)
392
411
optionalBasicAttrNillable?: int @go(,optional=nillable)
393
412
optionalListAttrNillable?: [...int] @go(,optional=nillable)
394
- optionalMapAttrNillable?: {[string]: int} @go(,optional=nillable)
413
+
414
+ // Ensure that "is nillable" is worked out correctly for inline types, referenced definitions,
415
+ // and nested types where only part of the type is not nillable, but not the top level.
416
+
417
+ optionalInlineMapAttrNillable?: {[string]: int} @go(,optional=nillable)
418
+ optionalLocalMapAttrNillable?: #localMap @go(,optional=nillable)
419
+ optionalInlineNestedAttrNillable?: {f?: [...string]} @go(,optional=nillable)
420
+ optionalLocalNestedAttrNillable?: #localNested @go(,optional=nillable)
395
421
396
422
optionalStruct?: #emptyStruct
397
423
optionalStructAttrType?: #emptyStruct @go(,type=EmptyStruct)
@@ -498,6 +524,9 @@ _#hiddenStruct: {
498
524
}
499
525
}
500
526
527
+ #localMap: [string]: int
528
+ #localNested: f?: [...string]
529
+
501
530
// Hidden definitions are only generated if referenced; this one is not.
502
531
_#unusedHiddenStruct: neverGenerate?: int
503
532
@@ -580,7 +609,7 @@ import (
580
609
"foo.test/bar/imported/unused"
581
610
)
582
611
583
- #remoteStructs : {
612
+ #rootImports : {
584
613
inst?: imported.#instanceStruct
585
614
586
615
lowerRegular?: imported.lowerRegular
@@ -590,6 +619,9 @@ import (
590
619
591
620
multiOne?: multipkg_one.#One
592
621
multiTwo?: multipkg_two.#Two
622
+
623
+ optionalRemoteMapAttrNillable?: imported.#remoteMap @go(,optional=nillable)
624
+ optionalRemoteNestedAttrNillable?: imported.#remoteNested @go(,optional=nillable)
593
625
}
594
626
595
627
_unusedImport: unused.#UnusedNeverGenerate
@@ -606,7 +638,7 @@ import (
606
638
"time"
607
639
)
608
640
609
- type RemoteStructs struct {
641
+ type RootImports struct {
610
642
Inst imported.InstanceStruct `json:"inst,omitempty"`
611
643
612
644
LowerRegular int64 `json:"lowerRegular,omitempty"`
@@ -620,6 +652,10 @@ type RemoteStructs struct {
620
652
MultiOne multipkg.One `json:"multiOne,omitempty"`
621
653
622
654
MultiTwo multipkg.Two `json:"multiTwo,omitempty"`
655
+
656
+ OptionalRemoteMapAttrNillable *imported.RemoteMap `json:"optionalRemoteMapAttrNillable,omitempty"`
657
+
658
+ OptionalRemoteNestedAttrNillable *imported.RemoteNested `json:"optionalRemoteNestedAttrNillable,omitempty"`
623
659
}
624
660
625
661
type Types struct {
@@ -703,11 +739,23 @@ type Root struct {
703
739
704
740
OptionalMap map[string]int64 `json:"optionalMap,omitempty"`
705
741
742
+ OptionalTopAttrNillable *any/* CUE top */ `json:"optionalTopAttrNillable,omitempty"`
743
+
744
+ OptionalNullAttrNillable **struct{}/* CUE null */ `json:"optionalNullAttrNillable,omitempty"`
745
+
706
746
OptionalBasicAttrNillable *int64 `json:"optionalBasicAttrNillable,omitempty"`
707
747
708
748
OptionalListAttrNillable *[]int64 `json:"optionalListAttrNillable,omitempty"`
709
749
710
- OptionalMapAttrNillable *map[string]int64 `json:"optionalMapAttrNillable,omitempty"`
750
+ OptionalInlineMapAttrNillable *map[string]int64 `json:"optionalInlineMapAttrNillable,omitempty"`
751
+
752
+ OptionalLocalMapAttrNillable *LocalMap `json:"optionalLocalMapAttrNillable,omitempty"`
753
+
754
+ OptionalInlineNestedAttrNillable *struct {
755
+ F *[]string `json:"f,omitempty"`
756
+ } `json:"optionalInlineNestedAttrNillable,omitempty"`
757
+
758
+ OptionalLocalNestedAttrNillable *LocalNested `json:"optionalLocalNestedAttrNillable,omitempty"`
711
759
712
760
OptionalStruct EmptyStruct `json:"optionalStruct,omitempty"`
713
761
@@ -804,6 +852,12 @@ type Root struct {
804
852
805
853
}
806
854
855
+ type LocalMap map[string]int64
856
+
857
+ type LocalNested struct {
858
+ F []string `json:"f,omitempty"`
859
+ }
860
+
807
861
type Root_innerStruct struct {
808
862
InnerStructField int64 `json:"innerStructField,omitempty"`
809
863
}
@@ -861,6 +915,9 @@ lowerRegular: int
861
915
UpperRegular: int
862
916
#lowerDef: int
863
917
#UpperDef: int
918
+
919
+ #remoteMap: [string]: int
920
+ #remoteNested: f?: [...string]
864
921
-- imported/subinst/cue_types_imported_gen.go.want --
865
922
// Code generated by "cue exp gengotypes"; DO NOT EDIT.
866
923
@@ -879,6 +936,12 @@ type InstanceStruct struct {
879
936
type LowerDef int64
880
937
881
938
type UpperDef int64
939
+
940
+ type RemoteMap map[string]int64
941
+
942
+ type RemoteNested struct {
943
+ F []string `json:"f,omitempty"`
944
+ }
882
945
-- imported/indirect/indirect.cue --
883
946
package indirect
884
947
0 commit comments