File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -2292,6 +2292,21 @@ func (v Value) Expr() (Op, []Value) {
2292
2292
a = append (a , remakeValue (v , env , x .Hi ))
2293
2293
op = SliceOp
2294
2294
case * adt.CallExpr :
2295
+ // Interpret "and" and "or" builtin semantically.
2296
+ if fn , ok := x .Fun .(* adt.Builtin ); ok && len (x .Args ) == 1 &&
2297
+ (fn .Name == "or" || fn .Name == "and" ) {
2298
+
2299
+ iter , _ := remakeValue (v , env , x .Args [0 ]).List ()
2300
+ for iter .Next () {
2301
+ a = append (a , iter .Value ())
2302
+ }
2303
+
2304
+ op = OrOp
2305
+ if fn .Name == "and" {
2306
+ op = AndOp
2307
+ }
2308
+ break
2309
+ }
2295
2310
a = append (a , remakeValue (v , env , x .Fun ))
2296
2311
for _ , arg := range x .Args {
2297
2312
a = append (a , remakeValue (v , env , arg ))
Original file line number Diff line number Diff line change @@ -3326,6 +3326,12 @@ func TestExpr(t *testing.T) {
3326
3326
}, {
3327
3327
input : `v: [...number] | *[1, 2, 3]` ,
3328
3328
want : `([...number]|*[1,2,3])` ,
3329
+ }, {
3330
+ input : `v: or([1, 2, 3])` ,
3331
+ want : `|(1 2 3)` ,
3332
+ }, {
3333
+ input : `v: and([1, 2, 3])` ,
3334
+ want : `&(1 2 3)` ,
3329
3335
}}
3330
3336
for _ , tc := range testCases {
3331
3337
t .Run (tc .input , func (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments