@@ -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:122 :2
191
+ ./root/root.cue:131 :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:122 :2
194
+ ./root/root.cue:131 :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):
@@ -282,12 +282,21 @@ func main() {
282
282
zeroRoot.DiscriminatorField = make(map[string]any)
283
283
284
284
// Optional fields which use the optional attribute flag.
285
+
285
286
zeroRoot.Fields.OptionalBasic = 5
286
287
zeroRoot.Fields.OptionalList = make([]int64, 0)
287
288
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)
289
+
290
+ zeroRoot.Fields.OptionalTopAttrNillable = (*any)(nil)
291
+ zeroRoot.Fields.OptionalNullAttrNillable = (**struct{})(nil)
292
+ zeroRoot.Fields.OptionalBasicAttrNillable = (*int64)(nil)
293
+ zeroRoot.Fields.OptionalListAttrNillable = (*[]int64)(nil)
294
+
295
+ zeroRoot.Fields.OptionalInlineMapAttrNillable = (*map[string]int64)(nil)
296
+ zeroRoot.Fields.OptionalNamedMapAttrNillable = (*root.NamedMap)(nil)
297
+ zeroRoot.Fields.OptionalInlineNestedAttrNillable = (*struct{F *[]string `json:"f,omitempty"`})(nil)
298
+ zeroRoot.Fields.OptionalNamedNestedAttrNillable = (*root.NamedNested)(nil)
299
+
291
300
zeroRoot.Fields.OptionalStruct = root.EmptyStruct{}
292
301
zeroRoot.Fields.OptionalStructAttrType = root.EmptyStruct{}
293
302
zeroRoot.Fields.OptionalStructAttrZero = root.EmptyStruct{}
@@ -389,9 +398,18 @@ _#overridenNeverGenerate: string
389
398
optionalList?: [...int]
390
399
optionalMap?: [string]: int
391
400
401
+ optionalTopAttrNillable?: _ @go(,optional=nillable)
402
+ optionalNullAttrNillable?: null @go(,optional=nillable)
392
403
optionalBasicAttrNillable?: int @go(,optional=nillable)
393
404
optionalListAttrNillable?: [...int] @go(,optional=nillable)
394
- optionalMapAttrNillable?: {[string]: int} @go(,optional=nillable)
405
+
406
+ // Ensure that "is nillable" is worked out correctly for inline types, referenced definitions,
407
+ // and nested types where only part of the type is not nillable, but not the top level.
408
+
409
+ optionalInlineMapAttrNillable?: {[string]: int} @go(,optional=nillable)
410
+ optionalNamedMapAttrNillable?: #namedMap @go(,optional=nillable)
411
+ optionalInlineNestedAttrNillable?: {f?: [...string]} @go(,optional=nillable)
412
+ optionalNamedNestedAttrNillable?: #namedNested @go(,optional=nillable)
395
413
396
414
optionalStruct?: #emptyStruct
397
415
optionalStructAttrType?: #emptyStruct @go(,type=EmptyStruct)
@@ -493,6 +511,10 @@ _#hiddenStruct: {
493
511
}
494
512
}
495
513
514
+ #namedMap: [string]: int
515
+
516
+ #namedNested: f?: [...string]
517
+
496
518
// Hidden definitions are only generated if referenced; this one is not.
497
519
_#unusedHiddenStruct: neverGenerate?: int
498
520
@@ -698,11 +720,23 @@ type Root struct {
698
720
699
721
OptionalMap map[string]int64 `json:"optionalMap,omitempty"`
700
722
723
+ OptionalTopAttrNillable *any/* CUE top */ `json:"optionalTopAttrNillable,omitempty"`
724
+
725
+ OptionalNullAttrNillable **struct{}/* CUE null */ `json:"optionalNullAttrNillable,omitempty"`
726
+
701
727
OptionalBasicAttrNillable *int64 `json:"optionalBasicAttrNillable,omitempty"`
702
728
703
729
OptionalListAttrNillable *[]int64 `json:"optionalListAttrNillable,omitempty"`
704
730
705
- OptionalMapAttrNillable *map[string]int64 `json:"optionalMapAttrNillable,omitempty"`
731
+ OptionalInlineMapAttrNillable *map[string]int64 `json:"optionalInlineMapAttrNillable,omitempty"`
732
+
733
+ OptionalNamedMapAttrNillable *NamedMap `json:"optionalNamedMapAttrNillable,omitempty"`
734
+
735
+ OptionalInlineNestedAttrNillable *struct {
736
+ F *[]string `json:"f,omitempty"`
737
+ } `json:"optionalInlineNestedAttrNillable,omitempty"`
738
+
739
+ OptionalNamedNestedAttrNillable *NamedNested `json:"optionalNamedNestedAttrNillable,omitempty"`
706
740
707
741
OptionalStruct EmptyStruct `json:"optionalStruct,omitempty"`
708
742
@@ -799,6 +833,12 @@ type Root struct {
799
833
800
834
}
801
835
836
+ type NamedMap map[string]int64
837
+
838
+ type NamedNested struct {
839
+ F []string `json:"f,omitempty"`
840
+ }
841
+
802
842
type Root_innerStruct struct {
803
843
InnerStructField int64 `json:"innerStructField,omitempty"`
804
844
}
0 commit comments