Program: 19199
Project: 19199
Buggy source:
/** 
 * Expect that the given variable has not been declared with a type.
 * @param sourceName The name of the source file we're in.
 * @param n The node where warnings should point to.
 * @param parent The parent of {@code n}.
 * @param var The variable that we're checking.
 * @param variableName The name of the variable.
 * @param newType The type being applied to the variable. Mostly just herefor the benefit of the warning.
 * @return The variable we end up with. Most of the time, this will justbe  {@code var}, but in some rare cases we will need to declare a new var with new source info.
 */
TypedVar expectUndeclaredVariable(String sourceName,CompilerInput input,Node n,Node parent,TypedVar var,String variableName,JSType newType){
  TypedVar newVar=var;
  JSType varType=var.getType();
  if (varType != null && varType != typeRegistry.getNativeType(UNKNOWN_TYPE) && newType != null && newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {
    if (var.input == null) {
      TypedScope s=var.getScope();
      s.undeclare(var);
      newVar=s.declare(variableName,n,varType,input,false);
      n.setJSType(varType);
      if (parent.isVar()) {
        if (n.hasChildren()) {
          n.getFirstChild().setJSType(varType);
        }
      }
 else {
        checkState(parent.isFunction());
        parent.setJSType(varType);
      }
    }
 else {
      boolean allowDupe=hasDuplicateDeclarationSuppression(compiler,var.getNameNode());
      if (!allowDupe) {
        if (!newType.isEquivalentTo(varType)) {
          report(JSError.make(n,DUP_VAR_DECLARATION_TYPE_MISMATCH,variableName,newType.toString(),var.getInputName(),String.valueOf(var.nameNode.getLineno()),varType.toString()));
        }
 else         if (!var.getParentNode().isExprResult()) {
          report(JSError.make(n,DUP_VAR_DECLARATION,variableName,var.getInputName(),String.valueOf(var.nameNode.getLineno())));
        }
      }
    }
  }
  return newVar;
}

Fixed version (ground truth):
/** 
 * Expect that the given variable has not been declared with a type.
 * @param sourceName The name of the source file we're in.
 * @param n The node where warnings should point to.
 * @param parent The parent of {@code n}.
 * @param var The variable that we're checking.
 * @param variableName The name of the variable.
 * @param newType The type being applied to the variable. Mostly just herefor the benefit of the warning.
 * @return The variable we end up with. Most of the time, this will justbe  {@code var}, but in some rare cases we will need to declare a new var with new source info.
 */
TypedVar expectUndeclaredVariable(String sourceName,CompilerInput input,Node n,Node parent,TypedVar var,String variableName,JSType newType){
  TypedVar newVar=var;
  JSType varType=var.getType();
  if (varType != null && varType != typeRegistry.getNativeType(UNKNOWN_TYPE) && newType != null && newType != typeRegistry.getNativeType(UNKNOWN_TYPE)) {
    if (var.input == null) {
      TypedScope s=var.getScope();
      s.undeclare(var);
      newVar=s.declare(variableName,n,varType,input,false);
      n.setJSType(varType);
      if (parent.isVar()) {
        if (n.hasChildren()) {
          n.getFirstChild().setJSType(varType);
        }
      }
 else {
        checkState(parent.isFunction());
        parent.setJSType(varType);
      }
    }
 else {
      boolean allowDupe=hasDuplicateDeclarationSuppression(compiler,var.getNameNode());
      if (!allowDupe) {
        if (!newType.isEquivalentTo(varType,true)) {
          report(JSError.make(n,DUP_VAR_DECLARATION_TYPE_MISMATCH,variableName,newType.toString(),var.getInputName(),String.valueOf(var.nameNode.getLineno()),varType.toString()));
        }
 else         if (!var.getParentNode().isExprResult()) {
          report(JSError.make(n,DUP_VAR_DECLARATION,variableName,var.getInputName(),String.valueOf(var.nameNode.getLineno())));
        }
      }
    }
  }
  return newVar;
}