cue: prevent crash in JSON conversion
Caught by new test set. Tests will come later.
Change-Id: I33daf892ac90c98284545386d0504f2c87f75f04
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/5820
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cue/types.go b/cue/types.go
index f21a7bd..7071dbe 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -936,8 +936,9 @@
if len(st.comprehensions) > 0 {
// This should always evaluate to incomplete. However, fall back
// to a bad error message, rather than crashing, in case it doesn't.
- err, _ := st.comprehensions[0].comp.evalPartial(ctx).(*bottom)
- return nil, toMarshalErr(v, err)
+ if err, ok := st.comprehensions[0].comp.evalPartial(ctx).(*bottom); ok {
+ return nil, toMarshalErr(v, err)
+ }
}
if err != nil {