fix for KT-2711 wrong check on descriptor being integral range
method added to JetStandardLibrary to get all integral range descriptors #KT-2711 fixed
This commit is contained in:
@@ -74,6 +74,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
|
||||
private static final String CLASS_NO_PATTERN_MATCHED_EXCEPTION = "jet/NoPatternMatchedException";
|
||||
private static final String CLASS_TYPE_CAST_EXCEPTION = "jet/TypeCastException";
|
||||
public static final Set<DeclarationDescriptor> INTEGRAL_RANGES = JetStandardLibrary.getInstance().getIntegralRanges();
|
||||
|
||||
private int myLastLineNumber = -1;
|
||||
|
||||
@@ -3535,13 +3536,7 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
JetType jetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, rangeExpression);
|
||||
assert jetType != null;
|
||||
final DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
|
||||
if (isClass(descriptor, "IntRange") ||
|
||||
isClass(descriptor, "CharRange") ||
|
||||
isClass(descriptor, "ByteRange") ||
|
||||
isClass(descriptor, "LongRange") ||
|
||||
isClass(descriptor, "ShortRange")) {
|
||||
return true;
|
||||
}
|
||||
return INTEGRAL_RANGES.contains(descriptor);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.jet.lang.types.lang;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
@@ -23,6 +24,7 @@ import com.intellij.psi.PsiFileFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
@@ -34,11 +36,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.JetTypeImpl;
|
||||
import org.jetbrains.jet.lang.types.TypeProjection;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.Variance;
|
||||
import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -218,6 +216,18 @@ public class JetStandardLibrary {
|
||||
jetArrayTypeToPrimitiveJetType.put(arrayType, type);
|
||||
}
|
||||
|
||||
public Set<DeclarationDescriptor> getIntegralRanges() {
|
||||
initStdClasses();
|
||||
|
||||
return ImmutableSet.<DeclarationDescriptor>of(
|
||||
getStdClassByName("ByteRange"),
|
||||
getStdClassByName("ShortRange"),
|
||||
getStdClassByName("CharRange"),
|
||||
getStdClassByName("IntRange"),
|
||||
getStdClassByName("LongRange")
|
||||
);
|
||||
}
|
||||
|
||||
public Collection<ClassDescriptor> getStandardTypes() {
|
||||
initStdClasses();
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
class IntRange {
|
||||
fun contains(a: Int) = (1..2).contains(a)
|
||||
}
|
||||
|
||||
class C() {
|
||||
fun rangeTo(i: Int) = IntRange()
|
||||
}
|
||||
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
if (2 in C()..2) {
|
||||
System.out?.println(2)
|
||||
}
|
||||
}
|
||||
@@ -533,4 +533,9 @@ public class ClassGenTest extends CodegenTestCase {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("regressions/kt1535.kt");
|
||||
}
|
||||
|
||||
public void testKt2711() {
|
||||
createEnvironmentWithMockJdkAndIdeaAnnotations(ConfigurationKind.JDK_ONLY);
|
||||
blackBoxFile("regressions/kt2711.kt");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user