cue: implement rewrite for unification type
This may be triggered as bounds are hard-coded
as unification and may be rewritten pre-evaluation.
Change-Id: I179775d885761a72dc933f7cc7629ccf7c9224d2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/1780
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/rewrite.go b/cue/rewrite.go
index 85130f4..c7a5e93 100644
--- a/cue/rewrite.go
+++ b/cue/rewrite.go
@@ -177,8 +177,16 @@
}
func (x *unification) rewrite(ctx *context, fn rewriteFunc) value {
- // Can a unification ever be rewritten as it is a post-evaluation type?
- panic("cue: unification only used post-evaluation")
+ values := make([]evaluated, len(x.values))
+ changed := false
+ for i, v := range x.values {
+ values[i] = rewrite(ctx, v, fn).(evaluated)
+ changed = changed || v != values[i]
+ }
+ if !changed {
+ return x
+ }
+ return &unification{x.baseValue, values}
}
func (x *disjunction) rewrite(ctx *context, fn rewriteFunc) value {