Allow $(filter ...) with arbitrary args if its result is compared to the empty string
Bug: 172923994 Test: internal Change-Id: Iea36ecaa8940cf4e495ad63125f10d733c3eb2ee
This commit is contained in:
@@ -240,22 +240,21 @@ func (eq *eqExpr) eval(valueMap map[string]starlarkExpr) (res starlarkExpr, same
|
||||
}
|
||||
|
||||
func (eq *eqExpr) emit(gctx *generationContext) {
|
||||
// Are we checking that a variable is empty?
|
||||
var varRef *variableRefExpr
|
||||
if s, ok := maybeString(eq.left); ok && s == "" {
|
||||
varRef, ok = eq.right.(*variableRefExpr)
|
||||
} else if s, ok := maybeString(eq.right); ok && s == "" {
|
||||
varRef, ok = eq.left.(*variableRefExpr)
|
||||
}
|
||||
if varRef != nil {
|
||||
// Yes.
|
||||
emitSimple := func(expr starlarkExpr) {
|
||||
if eq.isEq {
|
||||
gctx.write("not ")
|
||||
}
|
||||
varRef.emit(gctx)
|
||||
return
|
||||
expr.emit(gctx)
|
||||
}
|
||||
// Are we checking that a variable is empty?
|
||||
if isEmptyString(eq.left) {
|
||||
emitSimple(eq.right)
|
||||
return
|
||||
} else if isEmptyString(eq.right) {
|
||||
emitSimple(eq.left)
|
||||
return
|
||||
|
||||
}
|
||||
// General case
|
||||
eq.left.emit(gctx)
|
||||
if eq.isEq {
|
||||
@@ -578,3 +577,8 @@ func maybeConvertToStringList(expr starlarkExpr) starlarkExpr {
|
||||
}
|
||||
return expr
|
||||
}
|
||||
|
||||
func isEmptyString(expr starlarkExpr) bool {
|
||||
x, ok := expr.(*stringLiteralExpr)
|
||||
return ok && x.literal == ""
|
||||
}
|
||||
|
Reference in New Issue
Block a user