private Expression EqualizeTypesAndCombine(Expression expr1, Expression expr2, int errorPos, Func<Expression, Expression, Expression> combineResults)
{
if (expr1.Type != expr2.Type)
{
Expression expr1As2 = expr2 != NullLiteral ? PromoteExpression(expr1, expr2.Type, true) : null;
Expression expr2As1 = expr1 != NullLiteral ? PromoteExpression(expr2, expr1.Type, true) : null;
if (expr1As2 != null && expr2As1 == null)
{
expr1 = expr1As2;
}
else if (expr2As1 != null && expr1As2 == null)
{
expr2 = expr2As1;
}
else
{
string type1 = expr1 != NullLiteral ? expr1.Type.Name : "null";
string type2 = expr2 != NullLiteral ? expr2.Type.Name : "null";
if (expr1As2 != null)
throw ParseError(errorPos, Res.BothTypesConvertToOther(type1, type2));
throw ParseError(errorPos, Res.NeitherTypeConvertsToOther(type1, type2));
}
}
return combineResults(expr1, expr2);
}