Shorten or/and in expressions (#1939)

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
This commit is contained in:
ChristopherHX 2023-08-08 16:30:13 +02:00 committed by GitHub
parent 0b4c67a4aa
commit 73d5f78294
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 10 deletions

View File

@ -554,6 +554,10 @@ func (impl *interperterImpl) evaluateLogicalCompare(compareNode *actionlint.Logi
leftValue := reflect.ValueOf(left) leftValue := reflect.ValueOf(left)
if IsTruthy(left) == (compareNode.Kind == actionlint.LogicalOpNodeKindOr) {
return impl.getSafeValue(leftValue), nil
}
right, err := impl.evaluateNode(compareNode.Right) right, err := impl.evaluateNode(compareNode.Right)
if err != nil { if err != nil {
return nil, err return nil, err
@ -563,17 +567,8 @@ func (impl *interperterImpl) evaluateLogicalCompare(compareNode *actionlint.Logi
switch compareNode.Kind { switch compareNode.Kind {
case actionlint.LogicalOpNodeKindAnd: case actionlint.LogicalOpNodeKindAnd:
if IsTruthy(left) { return impl.getSafeValue(rightValue), nil
return impl.getSafeValue(rightValue), nil
}
return impl.getSafeValue(leftValue), nil
case actionlint.LogicalOpNodeKindOr: case actionlint.LogicalOpNodeKindOr:
if IsTruthy(left) {
return impl.getSafeValue(leftValue), nil
}
return impl.getSafeValue(rightValue), nil return impl.getSafeValue(rightValue), nil
} }