cue: fix bug when using multiple custom validators
Change-Id: I892b3351edd760e45c36710c651e21e68a988033
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2624
Reviewed-by: Marcel van Lohuizen <mpvl@google.com>
diff --git a/cue/binop.go b/cue/binop.go
index 1e487ab..3f081a4 100644
--- a/cue/binop.go
+++ b/cue/binop.go
@@ -510,6 +510,9 @@
}
return &unification{newSrc, []evaluated{x, y}}
+ case *customValidator:
+ return &unification{newSrc, []evaluated{x, y}}
+
case *bound:
return &unification{newSrc, []evaluated{x, y}}
@@ -534,7 +537,7 @@
return y
}
}
- return ctx.mkErr(src, "invalid operation %v and %v (operator not defined for custom validator)")
+ return ctx.mkErr(src, "invalid operation %v and %v (operator not defined for custom validator)", ctx.str(x), ctx.str(other))
}
func (x *customValidator) check(ctx *context, v evaluated) evaluated {
diff --git a/cue/resolve_test.go b/cue/resolve_test.go
index b1227c2..c44856d 100644
--- a/cue/resolve_test.go
+++ b/cue/resolve_test.go
@@ -738,10 +738,14 @@
b: strings.ContainsAny("c")
b: "dog"
+
+ c: strings.ContainsAny("d") & strings.ContainsAny("g")
+ c: "dog"
`,
out: `<0>{` +
`a: "after", ` +
- `b: _|_(strings.ContainsAny ("c"):invalid value "dog" (does not satisfy strings.ContainsAny("c")))` +
+ `b: _|_(strings.ContainsAny ("c"):invalid value "dog" (does not satisfy strings.ContainsAny("c"))), ` +
+ `c: "dog"` +
`}`,
}, {
desc: "null coalescing",
diff --git a/cue/types.go b/cue/types.go
index ca3bc09..84dcd3e 100644
--- a/cue/types.go
+++ b/cue/types.go
@@ -1616,6 +1616,12 @@
a = append(a, remakeValue(v, arg))
}
op = CallOp
+ case *customValidator:
+ a = append(a, remakeValue(v, x.call))
+ for _, arg := range x.args {
+ a = append(a, remakeValue(v, arg))
+ }
+ op = CallOp
default:
a = append(a, v)
}