1530 // arm is short, the other is char). |
1530 // arm is short, the other is char). |
1531 if (thenUnboxed.isPrimitive() && elseUnboxed.isPrimitive()) { |
1531 if (thenUnboxed.isPrimitive() && elseUnboxed.isPrimitive()) { |
1532 // If one arm has an integer subrange type (i.e., byte, |
1532 // If one arm has an integer subrange type (i.e., byte, |
1533 // short, or char), and the other is an integer constant |
1533 // short, or char), and the other is an integer constant |
1534 // that fits into the subrange, return the subrange type. |
1534 // that fits into the subrange, return the subrange type. |
1535 if (thenUnboxed.getTag().isStrictSubRangeOf(INT) && elseUnboxed.hasTag(INT) && |
1535 if (thenUnboxed.getTag().isStrictSubRangeOf(INT) && |
1536 types.isAssignable(elseUnboxed, thenUnboxed)) |
1536 elseUnboxed.hasTag(INT) && |
|
1537 types.isAssignable(elseUnboxed, thenUnboxed)) { |
1537 return thenUnboxed.baseType(); |
1538 return thenUnboxed.baseType(); |
1538 if (elseUnboxed.getTag().isStrictSubRangeOf(INT) && thenUnboxed.hasTag(INT) && |
1539 } |
1539 types.isAssignable(thenUnboxed, elseUnboxed)) |
1540 if (elseUnboxed.getTag().isStrictSubRangeOf(INT) && |
|
1541 thenUnboxed.hasTag(INT) && |
|
1542 types.isAssignable(thenUnboxed, elseUnboxed)) { |
1540 return elseUnboxed.baseType(); |
1543 return elseUnboxed.baseType(); |
1541 |
1544 } |
1542 for (TypeTag tag : TypeTag.values()) { |
1545 |
1543 if (tag.ordinal() >= TypeTag.getTypeTagCount()) break; |
1546 for (TypeTag tag : primitiveTags) { |
1544 Type candidate = syms.typeOfTag[tag.ordinal()]; |
1547 Type candidate = syms.typeOfTag[tag.ordinal()]; |
1545 if (candidate != null && |
1548 if (types.isSubtype(thenUnboxed, candidate) && |
1546 candidate.isPrimitive() && |
1549 types.isSubtype(elseUnboxed, candidate)) { |
1547 types.isSubtype(thenUnboxed, candidate) && |
|
1548 types.isSubtype(elseUnboxed, candidate)) |
|
1549 return candidate; |
1550 return candidate; |
|
1551 } |
1550 } |
1552 } |
1551 } |
1553 } |
1552 |
1554 |
1553 // Those were all the cases that could result in a primitive |
1555 // Those were all the cases that could result in a primitive |
1554 if (allowBoxing) { |
1556 if (allowBoxing) { |
1572 // both are known to be reference types. The result is |
1574 // both are known to be reference types. The result is |
1573 // lub(thentype,elsetype). This cannot fail, as it will |
1575 // lub(thentype,elsetype). This cannot fail, as it will |
1574 // always be possible to infer "Object" if nothing better. |
1576 // always be possible to infer "Object" if nothing better. |
1575 return types.lub(thentype.baseType(), elsetype.baseType()); |
1577 return types.lub(thentype.baseType(), elsetype.baseType()); |
1576 } |
1578 } |
|
1579 |
|
1580 final static TypeTag[] primitiveTags = new TypeTag[]{ |
|
1581 BYTE, |
|
1582 CHAR, |
|
1583 SHORT, |
|
1584 INT, |
|
1585 LONG, |
|
1586 FLOAT, |
|
1587 DOUBLE, |
|
1588 BOOLEAN, |
|
1589 }; |
1577 |
1590 |
1578 public void visitIf(JCIf tree) { |
1591 public void visitIf(JCIf tree) { |
1579 attribExpr(tree.cond, env, syms.booleanType); |
1592 attribExpr(tree.cond, env, syms.booleanType); |
1580 attribStat(tree.thenpart, env); |
1593 attribStat(tree.thenpart, env); |
1581 if (tree.elsepart != null) |
1594 if (tree.elsepart != null) |