Removed setConstType() from is isBoxingCall() to avoid hidden side effect

Const type is now adjusted correctly also when the target is
java.lang.Character or java.lang.Integer
This commit is contained in:
Dmitry Cherniachenko
2017-06-23 21:43:23 +02:00
committed by Egor.Ushakov
parent d382ba2709
commit 5db9ad29c8
6 changed files with 248 additions and 221 deletions

View File

@@ -369,16 +369,16 @@ public class ConstExprent extends Exprent {
public void adjustConstType(VarType expectedType) {
// BYTECHAR and SHORTCHAR => CHAR in the CHAR context
if (expectedType.equals(VarType.VARTYPE_CHAR) &&
if ((expectedType.equals(VarType.VARTYPE_CHAR) || expectedType.equals(VarType.VARTYPE_CHARACTER)) &&
(constType.equals(VarType.VARTYPE_BYTECHAR) || constType.equals(VarType.VARTYPE_SHORTCHAR))) {
int intValue = getIntValue();
if (isPrintableAscii(intValue) || CHAR_ESCAPES.containsKey(intValue)) {
setConstType(VarType.VARTYPE_CHAR);
}
}
// CHAR => INT in the INT context
else if (expectedType.equals(VarType.VARTYPE_INT) &&
constType.equals(VarType.VARTYPE_CHAR)) {
// BYTE, BYTECHAR, SHORTCHAR, SHORT, CHAR => INT in the INT context
else if ((expectedType.equals(VarType.VARTYPE_INT) || expectedType.equals(VarType.VARTYPE_INTEGER)) &&
constType.typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) {
setConstType(VarType.VARTYPE_INT);
}
}

View File

@@ -410,10 +410,10 @@ public class InvocationExprent extends Exprent {
// special handling for ambiguous types
if (lstParameters.get(0).type == Exprent.EXPRENT_CONST) {
// 'Integer.valueOf(1)' has '1' type detected as TYPE_BYTECHAR
// 'Integer.valueOf(40_000)' has '40_000' type detected as TYPE_CHAR
// so we check the type family instead
if (lstParameters.get(0).getExprType().typeFamily == CodeConstants.TYPE_FAMILY_INTEGER) {
if (classname.equals("java/lang/Integer")) {
// 'Integer.valueOf(40_000)' will change to '40_000' and that will be interpreted as 'char' type
((ConstExprent) lstParameters.get(0)).setConstType(VarType.VARTYPE_INT);
return true;
}
}

View File

@@ -38,6 +38,8 @@ public class VarType { // TODO: optimize switch
public static final VarType VARTYPE_STRING = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/String");
public static final VarType VARTYPE_CLASS = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Class");
public static final VarType VARTYPE_OBJECT = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Object");
public static final VarType VARTYPE_INTEGER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Integer");
public static final VarType VARTYPE_CHARACTER = new VarType(CodeConstants.TYPE_OBJECT, 0, "java/lang/Character");
public static final VarType VARTYPE_VOID = new VarType(CodeConstants.TYPE_VOID);
public final int type;