this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

encoding/jsonschema: fix panic on impossible enum

When all possible values of an enum are excluded by the allowed types we
were invoking s.all.add with a nil expression which resulted in a panic.

Fix that by avoiding adding the constraint in that case: the
allowedTypes logic will catch the "impossible constraint" option when
finalize is called.

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I0836d0444a24df62f6392261a5d5733387529ff6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199410
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

+11 -1
+3 -1
encoding/jsonschema/constraints.go
··· 204 204 } 205 205 s.knownTypes &= types 206 206 s.allowedTypes &= types 207 - s.all.add(n, ast.NewBinExpr(token.OR, a...)) 207 + if len(a) > 0 { 208 + s.all.add(n, ast.NewBinExpr(token.OR, a...)) 209 + } 208 210 }), 209 211 210 212 // TODO: only allow for OpenAPI.
+8
encoding/jsonschema/testdata/enumexcluded.txtar
··· 1 + -- type.json -- 2 + { 3 + "type": "object", 4 + "enum": ["x"] 5 + } 6 + -- out/decode/err -- 7 + constraints are not possible to satisfy: 8 + type.json:1:1