Skip to content

Commit a2d428d

Browse files
committed
pkg/list: MatchN matches in final mode
Matching is defined on final values. Make this analogous to matchN. Also change the second Validate to Err. Fixes #3519 Signed-off-by: Marcel van Lohuizen <mpvl@gmail.com> Change-Id: I7fe2f6f977e3c589db2aa0103256a4f64ab1ceb2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1204425 Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com> Reviewed-by: Roger Peppe <rogpeppe@gmail.com> TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
1 parent 38c6949 commit a2d428d

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pkg/list/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,15 @@ func Contains(a []cue.Value, v cue.Value) bool {
333333
func MatchN(list []cue.Value, n pkg.Schema, matchValue pkg.Schema) (bool, error) {
334334
var nmatch int64
335335
for _, w := range list {
336-
if matchValue.Unify(w).Validate() == nil {
336+
if matchValue.Unify(w).Validate(cue.Final()) == nil {
337337
nmatch++
338338
}
339339
}
340340

341341
r, _ := value.ToInternal(n)
342342
ctx := (*cue.Context)(r)
343343

344-
if err := n.Unify(ctx.Encode(nmatch)).Validate(); err != nil {
344+
if err := n.Unify(ctx.Encode(nmatch)).Err(); err != nil {
345345
return false, pkg.ValidationError{B: &adt.Bottom{
346346
Code: adt.EvalError,
347347
Err: errors.Newf(

pkg/list/testdata/matchn_err.txtar

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): n
4747
./in.cue:11:6
4848
./in.cue:4:12
4949
./in.cue:11:18
50+
issue3519.a: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1:
51+
./in.cue:16:8
52+
./in.cue:15:8
53+
./in.cue:16:20
5054

5155
Result:
5256
t1: {
@@ -58,7 +62,7 @@ t1: {
5862
l6: _|_ // t1.l6: invalid value [1,2,3,"str",[1],{foo:1}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy >0
5963
}
6064
issue3519: {
61-
a: [{}]
65+
a: _|_ // issue3519.a: invalid value [{}] (does not satisfy list.MatchN): number of matched elements is 0: does not satisfy 1
6266
}
6367
#TOO: {
6468
too: int

0 commit comments

Comments
 (0)