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:
committed by
Egor.Ushakov
parent
d382ba2709
commit
5db9ad29c8
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user