@@ -88,29 +88,28 @@ func assignable(sch cue.Value, T interface{}) error {
88
88
89
89
check = func (gval , sval cue.Value , p cue.Path ) {
90
90
sk , gk := sval .IncompleteKind (), gval .IncompleteKind ()
91
- schemaHadNull , goHadNull := sk & cue . NullKind != 0 , gk & cue .NullKind != 0
91
+ schemaHadNull := sk & cue .NullKind != 0
92
92
sk &^= cue .NullKind
93
93
gk &^= cue .NullKind
94
94
95
95
ogval := gval
96
- if goHadNull {
97
- // At least for now, we have to deal with these unhelpful *null
98
- // appearing in the encoding of pointer types.
99
- //
100
- // We can't do the same for the schema side, because this null stripper
101
- // relies on the fact that all actual Go type declarations will come across
102
- // as a single value, without any disjunctions.
103
- gval = stripLeadNull (gval )
104
- }
96
+ // At least for now, we have to deal with these unhelpful *null
97
+ // appearing in the encoding of pointer types.
98
+ //
99
+ // We can't do the same for the schema side, because this null stripper
100
+ // relies on the fact that all actual Go type declarations will come across
101
+ // as a single value, without any disjunctions.
102
+ gval = stripLeadNull (gval )
105
103
106
104
// strict equality _might_ be too restrictive? But it's better to start there
107
- if sk != gk && gk != cue .TopKind {
105
+ if sk != gk && gk != ( cue .TopKind ^ cue . NullKind ) {
108
106
errs [p .String ()] = fmt .Errorf ("%s: is kind %s in schema, but kind %s in Go type" , p , sk , gk )
109
107
return
110
- } else if gk == cue .TopKind {
108
+ } else if gk == ( cue .TopKind ^ cue . NullKind ) {
111
109
// Escape hatch for a Go interface{}/any
112
110
return
113
111
}
112
+ op , _ := sval .Expr ()
114
113
115
114
switch sk {
116
115
case cue .ListKind :
@@ -122,6 +121,10 @@ func assignable(sch cue.Value, T interface{}) error {
122
121
checkscalar (gval , sval , p )
123
122
}
124
123
case cue .StructKind :
124
+ if op == cue .OrOp {
125
+ errs [p .String ()] = fmt .Errorf ("%s: contains disjunction over struct types, but Go type is not any" , p )
126
+ return
127
+ }
125
128
checkstruct (gval , sval , p )
126
129
case cue .NullKind :
127
130
errs [p .String ()] = fmt .Errorf ("%s: null is not permitted in schema; express optionality with ?" , p )
0 commit comments