Program: 133248
Project: 133248
Buggy source:
private static ExprType uncachedFindExprType(Context context,SwiftAST tree) throws UserException {
  int token=tree.getType();
switch (token) {
case ExMParser.CALL_FUNCTION:
{
      return callFunction(context,tree,true);
    }
case ExMParser.VARIABLE:
{
    Variable var=context.getDeclaredVariable(tree.child(0).getText());
    if (var == null) {
      throw new UndefinedVariableException(context,"String_Node_Str" + tree.child(0).getText() + "String_Node_Str");
    }
    SwiftType exprType=var.getType();
    if (Types.isScalarUpdateable(exprType)) {
      return new ExprType(UnionType.createUnionType(exprType,ScalarUpdateableType.asScalarFuture(exprType)));
    }
    return new ExprType(exprType);
  }
case ExMParser.INT_LITERAL:
return new ExprType(UnionType.createUnionType(Types.FUTURE_INTEGER,Types.FUTURE_FLOAT));
case ExMParser.FLOAT_LITERAL:
return new ExprType(Types.FUTURE_FLOAT);
case ExMParser.STRING_LITERAL:
return new ExprType(Types.FUTURE_STRING);
case ExMParser.BOOL_LITERAL:
return new ExprType(Types.FUTURE_BOOLEAN);
case ExMParser.OPERATOR:
return findOperatorResultType(context,tree);
case ExMParser.STRUCT_LOAD:
ExprType structTypeL=findExprType(context,tree.child(0));
String fieldName=tree.child(1).getText();
if (structTypeL.elems() != 1) {
throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str");
}
SwiftType structType=structTypeL.get(0);
SwiftType fieldType;
fieldType=findStructFieldType(context,fieldName,structType);
if (fieldType == null) {
throw new TypeMismatchException(context,"String_Node_Str" + fieldName + "String_Node_Str"+ ((StructType)structType).getTypeName());
}
if (Types.isStruct(structType)) {
return new ExprType(fieldType);
}
 else {
assert(Types.isStructRef(structType));
return new ExprType(dereferenceResultType(fieldType));
}
case ExMParser.ARRAY_LOAD:
ExprType arrTypeL=findExprType(context,tree.child(0));
if (arrTypeL.elems() != 1) {
throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str");
}
SwiftType arrType=arrTypeL.get(0);
SwiftType memberType;
if (Types.isArray(arrType) || Types.isArrayRef(arrType)) {
memberType=Types.getArrayMemberType(arrType);
}
 else {
throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str" + arrType.toString());
}
SwiftType resultType;
resultType=dereferenceResultType(memberType);
return new ExprType(resultType);
case ExMParser.ARRAY_RANGE:
{
ArrayRange ar=ArrayRange.fromAST(context,tree);
ar.typeCheck(context);
return new ExprType(new ArrayType(Types.FUTURE_INTEGER));
}
case ExMParser.ARRAY_ELEMS:
{
return ArrayElems.fromAST(context,tree).getType(context);
}
default :
throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(token));
}
}

Fixed version (ground truth):
private static ExprType uncachedFindExprType(Context context,SwiftAST tree) throws UserException {
  int token=tree.getType();
switch (token) {
case ExMParser.CALL_FUNCTION:
{
      return callFunction(context,tree,true);
    }
case ExMParser.VARIABLE:
{
    Variable var=context.getDeclaredVariable(tree.child(0).getText());
    if (var == null) {
      throw new UndefinedVariableException(context,"String_Node_Str" + tree.child(0).getText() + "String_Node_Str");
    }
    SwiftType exprType=var.getType();
    if (Types.isScalarUpdateable(exprType)) {
      return new ExprType(UnionType.createUnionType(exprType,ScalarUpdateableType.asScalarFuture(exprType)));
    }
    return new ExprType(exprType);
  }
case ExMParser.INT_LITERAL:
return new ExprType(UnionType.createUnionType(Types.FUTURE_INTEGER,Types.FUTURE_FLOAT));
case ExMParser.FLOAT_LITERAL:
return new ExprType(Types.FUTURE_FLOAT);
case ExMParser.STRING_LITERAL:
return new ExprType(Types.FUTURE_STRING);
case ExMParser.BOOL_LITERAL:
return new ExprType(Types.FUTURE_BOOLEAN);
case ExMParser.OPERATOR:
return findOperatorResultType(context,tree);
case ExMParser.STRUCT_LOAD:
ExprType structTypeL=findExprType(context,tree.child(0));
String fieldName=tree.child(1).getText();
if (structTypeL.elems() != 1) {
throw new TypeMismatchException(context,"String_Node_Str" + "String_Node_Str");
}
SwiftType structType=structTypeL.get(0);
SwiftType fieldType;
fieldType=findStructFieldType(context,fieldName,structType);
if (fieldType == null) {
throw new TypeMismatchException(context,"String_Node_Str" + fieldName + "String_Node_Str"+ ((StructType)structType).getTypeName());
}
if (Types.isStruct(structType)) {
return new ExprType(fieldType);
}
 else {
assert(Types.isStructRef(structType));
return new ExprType(dereferenceResultType(fieldType));
}
case ExMParser.ARRAY_LOAD:
SwiftType arrType=findSingleExprType(context,tree.child(0));
List<SwiftType> resultAlts=new ArrayList<SwiftType>();
for (SwiftType arrAlt : UnionType.getAlternatives(arrType)) {
if (Types.isArray(arrAlt) || Types.isArrayRef(arrAlt)) {
SwiftType memberType=Types.getArrayMemberType(arrAlt);
resultAlts.add(dereferenceResultType(memberType));
}
 else {
throw new TypeMismatchException(context,"String_Node_Str" + arrType.toString());
}
}
return new ExprType(UnionType.makeUnion(resultAlts));
case ExMParser.ARRAY_RANGE:
{
ArrayRange ar=ArrayRange.fromAST(context,tree);
ar.typeCheck(context);
return new ExprType(new ArrayType(Types.FUTURE_INTEGER));
}
case ExMParser.ARRAY_ELEMS:
{
return ArrayElems.fromAST(context,tree).getType(context);
}
default :
throw new STCRuntimeError("String_Node_Str" + LogHelper.tokName(token));
}
}