Fixed 'IDEA-128594: Variable type incorrectly set to boolean'

This commit is contained in:
Stiver 2014-08-13 22:03:09 +02:00
parent 70bf7f3f69
commit de249340fc
2 changed files with 61 additions and 39 deletions

View File

@ -369,40 +369,45 @@ public class FunctionExprent extends Exprent {
case FUNCTION_AND:
case FUNCTION_OR:
case FUNCTION_XOR:
if(type1.type == CodeConstants.TYPE_BOOLEAN &&
((type1.convinfo & VarType.FALSEBOOLEAN) != 0 || type2.type != CodeConstants.TYPE_BOOLEAN)) {
{
boolean param1_false_boolean = type1.isFalseBoolean() || (param1.type == Exprent.EXPRENT_CONST && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean = type1.isFalseBoolean() || (param2.type == Exprent.EXPRENT_CONST && !((ConstExprent)param2).hasBooleanValue());
if(param1_false_boolean || param2_false_boolean) {
if(type1.type == CodeConstants.TYPE_BOOLEAN) {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
}
if(type2.type == CodeConstants.TYPE_BOOLEAN &&
((type2.convinfo & VarType.FALSEBOOLEAN) != 0 || type1.type != CodeConstants.TYPE_BOOLEAN)) {
if(type2.type == CodeConstants.TYPE_BOOLEAN) {
result.addMinTypeExprent(param2, VarType.VARTYPE_BYTECHAR);
}
}
}
break;
case FUNCTION_EQ:
case FUNCTION_NE:
{
if(type1.type == CodeConstants.TYPE_BOOLEAN) {
if(type2.isStrictSuperset(type1)) {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
} else {
if(param1.type == Exprent.EXPRENT_CONST && !((ConstExprent)param1).hasBooleanValue()) {
if(param2.type != Exprent.EXPRENT_CONST || !((ConstExprent)param2).hasBooleanValue()) { // variable or not boolean constant
} else { // both are booleans
boolean param1_false_boolean = type1.isFalseBoolean() || (param1.type == Exprent.EXPRENT_CONST && !((ConstExprent)param1).hasBooleanValue());
boolean param2_false_boolean = type1.isFalseBoolean() || (param2.type == Exprent.EXPRENT_CONST && !((ConstExprent)param2).hasBooleanValue());
if(param1_false_boolean || param2_false_boolean) {
result.addMinTypeExprent(param1, VarType.VARTYPE_BYTECHAR);
}
}
result.addMinTypeExprent(param2, VarType.VARTYPE_BYTECHAR);
}
}
if(type2.type == CodeConstants.TYPE_BOOLEAN) {
} else if(type2.type == CodeConstants.TYPE_BOOLEAN) {
if(type1.isStrictSuperset(type2)) {
result.addMinTypeExprent(param2, VarType.VARTYPE_BYTECHAR);
} else {
if(param2.type == Exprent.EXPRENT_CONST && !((ConstExprent)param2).hasBooleanValue()) {
if(param1.type != Exprent.EXPRENT_CONST || !((ConstExprent)param1).hasBooleanValue()) { // variable or not boolean constant
result.addMinTypeExprent(param2, VarType.VARTYPE_BYTECHAR);
}
}
}
}

View File

@ -115,6 +115,10 @@ public class VarType { // TODO: optimize switch
return v;
}
public boolean isFalseBoolean() {
return (convinfo & VarType.FALSEBOOLEAN) != 0;
}
public boolean isSuperset(VarType val) {
return this.equals(val) || this.isStrictSuperset(val);
@ -165,6 +169,10 @@ public class VarType { // TODO: optimize switch
// type1 and type2 must not be null
public static VarType getCommonMinType(VarType type1, VarType type2) {
if(type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans
return type1.isFalseBoolean() ? type2 : type1;
}
if(type1.isSuperset(type2)) {
return type2;
} else if(type2.isSuperset(type1)) {
@ -189,6 +197,10 @@ public class VarType { // TODO: optimize switch
// type1 and type2 must not be null
public static VarType getCommonSupertype(VarType type1, VarType type2) {
if(type1.type == CodeConstants.TYPE_BOOLEAN && type2.type == CodeConstants.TYPE_BOOLEAN) { // special case booleans
return type1.isFalseBoolean() ? type1 : type2;
}
if(type1.isSuperset(type2)) {
return type1;
} else if(type2.isSuperset(type1)) {
@ -232,12 +244,17 @@ public class VarType { // TODO: optimize switch
}
public boolean equals(Object o) {
if(o == this) return true;
if(o == null || !(o instanceof VarType)) return false;
VarType vt = (VarType)o;
return type == vt.type && arraydim == vt.arraydim &&
InterpreterUtil.equalObjects(value, vt.value);
if(o == this) {
return true;
}
if(o == null || !(o instanceof VarType)) {
return false;
}
VarType vt = (VarType) o;
return type == vt.type && arraydim == vt.arraydim && InterpreterUtil.equalObjects(value, vt.value);
}
private void parseTypeString(String strtype, boolean cltype) {