Allow $(filter ...) with arbitrary args if its result is compared to the empty string

Bug: 172923994
Test: internal
Change-Id: Iea36ecaa8940cf4e495ad63125f10d733c3eb2ee
diff --git a/mk2rbc/expr.go b/mk2rbc/expr.go
index b06ed90..915f69e 100644
--- a/mk2rbc/expr.go
+++ b/mk2rbc/expr.go
@@ -240,22 +240,21 @@
 }
 
 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 @@
 	}
 	return expr
 }
+
+func isEmptyString(expr starlarkExpr) bool {
+	x, ok := expr.(*stringLiteralExpr)
+	return ok && x.literal == ""
+}