Program: 27865
Project: 27865
Buggy source:
/** 
 * @see #createFromTypeNodes(Node,String,StaticScope) 
 */
private JSType createFromTypeNodesInternal(Node n,String sourceName,StaticScope<JSType> scope){
switch (n.getType()) {
case Token.LC:
    return createRecordTypeFromNodes(n.getFirstChild(),sourceName,scope);
case Token.BANG:
  return createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope).restrictByNotNullOrUndefined();
case Token.QMARK:
Node firstChild=n.getFirstChild();
if (firstChild == null) {
return getNativeType(UNKNOWN_TYPE);
}
return createDefaultObjectUnion(createFromTypeNodesInternal(firstChild,sourceName,scope));
case Token.EQUALS:
return createOptionalType(createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope));
case Token.ELLIPSIS:
return createOptionalType(createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope));
case Token.STAR:
return getNativeType(ALL_TYPE);
case Token.LB:
return getNativeType(ARRAY_TYPE);
case Token.PIPE:
UnionTypeBuilder builder=new UnionTypeBuilder(this);
for (Node child=n.getFirstChild(); child != null; child=child.getNext()) {
builder.addAlternate(createFromTypeNodesInternal(child,sourceName,scope));
}
return builder.build();
case Token.EMPTY:
return getNativeType(UNKNOWN_TYPE);
case Token.VOID:
return getNativeType(VOID_TYPE);
case Token.STRING:
JSType namedType=getType(scope,n.getString(),sourceName,n.getLineno(),n.getCharno());
if (resolveMode != ResolveMode.LAZY_NAMES) {
namedType=namedType.resolveInternal(reporter,scope);
}
if ((namedType instanceof ObjectType) && !(nonNullableTypeNames.contains(n.getString()))) {
Node typeList=n.getFirstChild();
int nAllowedTypes=namedType.getTemplateTypeMap().numUnfilledTemplateKeys();
if (typeList != null && nAllowedTypes > 0) {
ImmutableList.Builder<JSType> templateTypes=ImmutableList.builder();
if (n.getString().equals("String_Node_Str") && typeList.getFirstChild() == typeList.getLastChild()) {
templateTypes.add(getNativeType(UNKNOWN_TYPE));
}
int templateNodeIndex=0;
for (Node templateNode : typeList.getFirstChild().siblings()) {
if (++templateNodeIndex > nAllowedTypes) {
break;
}
templateTypes.add(createFromTypeNodesInternal(templateNode,sourceName,scope));
}
namedType=createTemplatizedType((ObjectType)namedType,templateTypes.build());
Preconditions.checkNotNull(namedType);
}
return createDefaultObjectUnion(namedType);
}
 else {
return namedType;
}
case Token.FUNCTION:
ObjectType thisType=null;
boolean isConstructor=false;
Node current=n.getFirstChild();
if (current.getType() == Token.THIS || current.getType() == Token.NEW) {
Node contextNode=current.getFirstChild();
thisType=ObjectType.cast(createFromTypeNodesInternal(contextNode,sourceName,scope).restrictByNotNullOrUndefined());
if (thisType == null) {
reporter.warning(SimpleErrorReporter.getMessage0(current.getType() == Token.THIS ? "String_Node_Str" : "String_Node_Str"),sourceName,contextNode.getLineno(),contextNode.getCharno());
}
isConstructor=current.getType() == Token.NEW;
current=current.getNext();
}
FunctionParamBuilder paramBuilder=new FunctionParamBuilder(this);
if (current.getType() == Token.PARAM_LIST) {
for (Node arg=current.getFirstChild(); arg != null; arg=arg.getNext()) {
if (arg.getType() == Token.ELLIPSIS) {
if (arg.getChildCount() == 0) {
paramBuilder.addVarArgs(getNativeType(UNKNOWN_TYPE));
}
 else {
paramBuilder.addVarArgs(createFromTypeNodesInternal(arg.getFirstChild(),sourceName,scope));
}
}
 else {
JSType type=createFromTypeNodesInternal(arg,sourceName,scope);
if (arg.getType() == Token.EQUALS) {
boolean addSuccess=paramBuilder.addOptionalParams(type);
if (!addSuccess) {
reporter.warning(SimpleErrorReporter.getMessage0("String_Node_Str"),sourceName,arg.getLineno(),arg.getCharno());
}
}
 else {
paramBuilder.addRequiredParams(type);
}
}
}
current=current.getNext();
}
JSType returnType=createFromTypeNodesInternal(current,sourceName,scope);
return new FunctionBuilder(this).withParams(paramBuilder).withReturnType(returnType).withTypeOfThis(thisType).setIsConstructor(isConstructor).build();
}
throw new IllegalStateException("String_Node_Str" + n.toString());
}

Fixed version (ground truth):
/** 
 * @see #createFromTypeNodes(Node,String,StaticScope) 
 */
private JSType createFromTypeNodesInternal(Node n,String sourceName,StaticScope<JSType> scope){
switch (n.getType()) {
case Token.LC:
    return createRecordTypeFromNodes(n.getFirstChild(),sourceName,scope);
case Token.BANG:
  return createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope).restrictByNotNullOrUndefined();
case Token.QMARK:
Node firstChild=n.getFirstChild();
if (firstChild == null) {
return getNativeType(UNKNOWN_TYPE);
}
return createDefaultObjectUnion(createFromTypeNodesInternal(firstChild,sourceName,scope));
case Token.EQUALS:
return createOptionalType(createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope));
case Token.ELLIPSIS:
return createOptionalType(createFromTypeNodesInternal(n.getFirstChild(),sourceName,scope));
case Token.STAR:
return getNativeType(ALL_TYPE);
case Token.LB:
return getNativeType(ARRAY_TYPE);
case Token.PIPE:
UnionTypeBuilder builder=new UnionTypeBuilder(this);
for (Node child=n.getFirstChild(); child != null; child=child.getNext()) {
builder.addAlternate(createFromTypeNodesInternal(child,sourceName,scope));
}
return builder.build();
case Token.EMPTY:
return getNativeType(UNKNOWN_TYPE);
case Token.VOID:
return getNativeType(VOID_TYPE);
case Token.STRING:
JSType namedType=getType(scope,n.getString(),sourceName,n.getLineno(),n.getCharno());
if ((namedType instanceof ObjectType) && !(nonNullableTypeNames.contains(n.getString()))) {
Node typeList=n.getFirstChild();
int nAllowedTypes=namedType.getTemplateTypeMap().numUnfilledTemplateKeys();
if (typeList != null && nAllowedTypes > 0) {
ImmutableList.Builder<JSType> templateTypes=ImmutableList.builder();
if (n.getString().equals("String_Node_Str") && typeList.getFirstChild() == typeList.getLastChild()) {
templateTypes.add(getNativeType(UNKNOWN_TYPE));
}
int templateNodeIndex=0;
for (Node templateNode : typeList.getFirstChild().siblings()) {
if (++templateNodeIndex > nAllowedTypes) {
break;
}
templateTypes.add(createFromTypeNodesInternal(templateNode,sourceName,scope));
}
namedType=createTemplatizedType((ObjectType)namedType,templateTypes.build());
Preconditions.checkNotNull(namedType);
}
return createDefaultObjectUnion(namedType);
}
 else {
return namedType;
}
case Token.FUNCTION:
ObjectType thisType=null;
boolean isConstructor=false;
Node current=n.getFirstChild();
if (current.getType() == Token.THIS || current.getType() == Token.NEW) {
Node contextNode=current.getFirstChild();
thisType=ObjectType.cast(createFromTypeNodesInternal(contextNode,sourceName,scope).restrictByNotNullOrUndefined());
if (thisType == null) {
reporter.warning(SimpleErrorReporter.getMessage0(current.getType() == Token.THIS ? "String_Node_Str" : "String_Node_Str"),sourceName,contextNode.getLineno(),contextNode.getCharno());
}
isConstructor=current.getType() == Token.NEW;
current=current.getNext();
}
FunctionParamBuilder paramBuilder=new FunctionParamBuilder(this);
if (current.getType() == Token.PARAM_LIST) {
for (Node arg=current.getFirstChild(); arg != null; arg=arg.getNext()) {
if (arg.getType() == Token.ELLIPSIS) {
if (arg.getChildCount() == 0) {
paramBuilder.addVarArgs(getNativeType(UNKNOWN_TYPE));
}
 else {
paramBuilder.addVarArgs(createFromTypeNodesInternal(arg.getFirstChild(),sourceName,scope));
}
}
 else {
JSType type=createFromTypeNodesInternal(arg,sourceName,scope);
if (arg.getType() == Token.EQUALS) {
boolean addSuccess=paramBuilder.addOptionalParams(type);
if (!addSuccess) {
reporter.warning(SimpleErrorReporter.getMessage0("String_Node_Str"),sourceName,arg.getLineno(),arg.getCharno());
}
}
 else {
paramBuilder.addRequiredParams(type);
}
}
}
current=current.getNext();
}
JSType returnType=createFromTypeNodesInternal(current,sourceName,scope);
return new FunctionBuilder(this).withParams(paramBuilder).withReturnType(returnType).withTypeOfThis(thisType).setIsConstructor(isConstructor).build();
}
throw new IllegalStateException("String_Node_Str" + n.toString());
}