From b0c6204c4df04712dab6195a83d8a46cf230200a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 26 Dec 2024 16:59:39 +0000 Subject: [PATCH] pkg/list: add a regression test for an invalid operand bug fixed in evalv3 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The added test case should fail with an invalid operand error, and evalv3 does so whereas evalv2 silently does nothing. Closes #3541. Signed-off-by: Daniel Martí Change-Id: Ic1a36f26d615533e8fcc3154b8103afa00e37306 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1206350 Reviewed-by: Marcel van Lohuizen Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo --- pkg/list/testdata/issues.txtar | 79 ++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/pkg/list/testdata/issues.txtar b/pkg/list/testdata/issues.txtar index d2b072beb..d965d5ad7 100644 --- a/pkg/list/testdata/issues.txtar +++ b/pkg/list/testdata/issues.txtar @@ -30,6 +30,84 @@ issue1404: { a: *1 | 2 sum: list.Sum([a]) } +issue3541: { + _test: { + one: { + num: 2 + test: num: 6 + } + two: { + num: 3 + test: num: 7 + } + three: { + num: 4 + test: num: 8 + } + four: { + num: 5 + test: num: 9 + } + } + + list.Sum([for key, val in _test { + val.num + val.test + }]) +} +-- out/list-v3 -- +Errors: +0: invalid operands 2 and {num:6} to '+' (type int and struct): + ./in.cue:53:3 + ./in.cue:35:9 + ./in.cue:36:10 + +Result: +issue563: { + #MyDef: { + name: string + } + output: [{ + name: "a" + }, { + name: "b" + }, { + name: "c" + }, { + name: "1" + }, { + name: "2" + }, { + name: "3" + }] +} +issue1404: { + a: *1 | 2 + sum: 1 +} +issue3541: _|_ // 0: invalid operands 2 and {num:6} to '+' (type int and struct) +-- diff/-out/list-v3<==>+out/list -- +diff old new +--- old ++++ new +@@ -1,3 +1,10 @@ ++Errors: ++0: invalid operands 2 and {num:6} to '+' (type int and struct): ++ ./in.cue:53:3 ++ ./in.cue:35:9 ++ ./in.cue:36:10 ++ ++Result: + issue563: { + #MyDef: { + name: string +@@ -20,4 +27,4 @@ + a: *1 | 2 + sum: 1 + } +-issue3541: {} ++issue3541: _|_ // 0: invalid operands 2 and {num:6} to '+' (type int and struct) +-- diff/explanation -- +issue3541: evalv3 correctly spots an invalid operand error which evalv2 drops on the floor. -- out/list -- issue563: { #MyDef: { @@ -53,3 +131,4 @@ issue1404: { a: *1 | 2 sum: 1 } +issue3541: {}