From 73d5f78294b046c176df20dd9233126350c96b5c Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Tue, 8 Aug 2023 16:30:13 +0200 Subject: [PATCH] Shorten or/and in expressions (#1939) Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/exprparser/interpreter.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/pkg/exprparser/interpreter.go b/pkg/exprparser/interpreter.go index 8bf4e57..feff80f 100644 --- a/pkg/exprparser/interpreter.go +++ b/pkg/exprparser/interpreter.go @@ -554,6 +554,10 @@ func (impl *interperterImpl) evaluateLogicalCompare(compareNode *actionlint.Logi leftValue := reflect.ValueOf(left) + if IsTruthy(left) == (compareNode.Kind == actionlint.LogicalOpNodeKindOr) { + return impl.getSafeValue(leftValue), nil + } + right, err := impl.evaluateNode(compareNode.Right) if err != nil { return nil, err @@ -563,17 +567,8 @@ func (impl *interperterImpl) evaluateLogicalCompare(compareNode *actionlint.Logi switch compareNode.Kind { case actionlint.LogicalOpNodeKindAnd: - if IsTruthy(left) { - return impl.getSafeValue(rightValue), nil - } - - return impl.getSafeValue(leftValue), nil - + return impl.getSafeValue(rightValue), nil case actionlint.LogicalOpNodeKindOr: - if IsTruthy(left) { - return impl.getSafeValue(leftValue), nil - } - return impl.getSafeValue(rightValue), nil }