IDEA-168578 Broken type inference in range expressions

This commit is contained in:
alexey.afanasiev
2017-02-22 12:24:36 +03:00
parent 7cba090767
commit 62f847da51
3 changed files with 24 additions and 3 deletions
@@ -139,6 +139,11 @@ public class PsiPrimitiveType extends PsiType.Stub {
return unboxed.annotate(type.getAnnotationProvider());
}
@Nullable
public static PsiPrimitiveType getOptionallyUnboxedType(PsiType type) {
return type instanceof PsiPrimitiveType ? (PsiPrimitiveType)type : getUnboxedType(type);
}
public String getBoxedTypeName() {
return ourUnboxedToQName.get(this);
}
@@ -558,14 +558,14 @@ public class TypesUtil implements TypeConstants {
@Nullable
private static PsiType getNumericLUB(@Nullable PsiType type1, @Nullable PsiType type2) {
PsiPrimitiveType unboxedType1 = PsiPrimitiveType.getUnboxedType(type1);
PsiPrimitiveType unboxedType2 = PsiPrimitiveType.getUnboxedType(type2);
PsiPrimitiveType unboxedType1 = PsiPrimitiveType.getOptionallyUnboxedType(type1);
PsiPrimitiveType unboxedType2 = PsiPrimitiveType.getOptionallyUnboxedType(type2);
if (unboxedType1 != null && unboxedType2 != null) {
int i1 = LUB_NUMERIC_TYPES.indexOf(unboxedType1);
int i2 = LUB_NUMERIC_TYPES.indexOf(unboxedType2);
if (i1 >= 0 && i2 >= 0) {
if (i1 > i2) return type1;
if (i2 > i1) return type2;
if (i2 >= i1) return type2;
}
}
return null;
@@ -597,6 +597,22 @@ class Any {
''', 'java.lang.Object')
}
void testRange() {
doTest('''\
def m = new int[3]
for (ii in 0..<m.length) {
print i<caret>i
}
''', 'java.lang.Integer')
doTest('''\
def m = new int[3]
for (ii in m.size()..< m[0]) {
print i<caret>i
}
''', 'java.lang.Integer')
}
void testUnary() {
doExprTest('~/abc/', 'java.util.regex.Pattern')
}