mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-168578 Broken type inference in range expressions
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
+16
@@ -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')
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user