anchor.diff:          // TODO (ajcbik): Remove restriction once compiler is fixed.
           if (depth < 2) {
             emit('...'); // spread
  -          emitCollection(depth + 1, tp);
  +          emitCollection(depth + 1, tp, rhsFilter: rhsFilter);
           } else {
  -          emitElement(depth, tp);
  +          emitElement(depth, tp, rhsFilter: rhsFilter);
           }
           break;
         case 1:
           emit('if (');
  -        emitElementExpr(depth + 1, DartType.BOOL);
  +        emitElementExpr(depth + 1, DartType.BOOL, rhsFilter: rhsFilter);
           emit(') ');
  -        emitCollectionElement(depth + 1, tp);
  +        emitCollectionElement(depth + 1, tp, rhsFilter: rhsFilter);
           if (rand.nextBool()) {
             emit(' else ');
  -          emitCollectionElement(depth + 1, tp);
  +          emitCollectionElement(depth + 1, tp, rhsFilter: rhsFilter);
           }
           break;
         case 2:
  
positive.code:         }
        }
      }
      // Then pick one.
      assert(choices.isNotEmpty);
      final emittedVar = '${choices.elementAt(rand.nextInt(choices.length))}';
      emit(emittedVar);
      return emittedVar;
    }
  
    void emitSubscriptedVar(int depth, DartType tp, {bool isLhs = false}) {
      if (tp == DartType.INT) {
        emitScalarVar(DartType.INT_LIST, isLhs: isLhs);
        emit('[');
        emitExpr(depth + 1, DartType.INT);
        emit(']');
      } else if (tp == DartType.STRING) {
        emitScalarVar(DartType.INT_STRING_MAP, isLhs: isLhs);
        emit('[');
        emitExpr(depth + 1, DartType.INT);
        emit(']');
      } else {
        emitScalarVar(tp, isLhs: isLhs); // resort to scalar
      }
    }
  
    void emitVar(int depth, DartType tp, {bool isLhs = false}) {
      switch (rand.nextInt(2)) {
        case 0:
          emitScalarVar(tp, isLhs: isLhs);
          break;
        default:
          emitSubscriptedVar(depth, tp, isLhs: isLhs);
          break;
      }
    }
  
    void emitTerminal(int depth, DartType tp) {
      switch (rand.nextInt(2)) {
        case 0:
          emitLiteral(depth, tp);
          break;
        default:
          emitVar(depth, tp);
          break;
      }
    }
  
    void emitExprList(int depth, List<DartType> proto) {
      emit('(');
      for (int i = 1; i < proto.length; i++) {
        emitExpr(depth, proto[i]);
        if (i != (proto.length - 1)) {
          emit(', ');
        }
  
negative.code:     } else if (tp == DartType.INT_LIST ||
          tp == DartType.INT_SET ||
          tp == DartType.INT_STRING_MAP) {
        emitCollection(depth, tp, rhsFilter: rhsFilter);
      } else {
        assert(false);
      }
    }
  
    String emitScalarVar(DartType tp, {bool isLhs = false, RhsFilter rhsFilter}) {
      // Collect all choices from globals, fields, locals, and parameters.
      Set<String> choices = <String>{};
      for (int i = 0; i < globalVars.length; i++) {
  