Delete Hashable, pull up its members to Any
Extensions on nullable types remain in Library.kt #KT-1741 Obsolete #KT-2805 Obsolete #KT-1365 Fixed #KT-4517 In Progress
This commit is contained in:
@@ -632,30 +632,58 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassToStringIfNeeded(List<PropertyDescriptor> properties) {
|
||||
private void generateDataClassToStringIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor stringClass = KotlinBuiltIns.getInstance().getString();
|
||||
if (getDeclaredFunctionByRawSignature(descriptor, Name.identifier("toString"), stringClass) == null) {
|
||||
if (!hasDeclaredNonTrivialMember("toString", stringClass)) {
|
||||
generateDataClassToStringMethod(properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassHashCodeIfNeeded(List<PropertyDescriptor> properties) {
|
||||
private void generateDataClassHashCodeIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor intClass = KotlinBuiltIns.getInstance().getInt();
|
||||
if (getDeclaredFunctionByRawSignature(descriptor, Name.identifier("hashCode"), intClass) == null) {
|
||||
if (!hasDeclaredNonTrivialMember("hashCode", intClass)) {
|
||||
generateDataClassHashCodeMethod(properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassEqualsIfNeeded(List<PropertyDescriptor> properties) {
|
||||
private void generateDataClassEqualsIfNeeded(@NotNull List<PropertyDescriptor> properties) {
|
||||
ClassDescriptor booleanClass = KotlinBuiltIns.getInstance().getBoolean();
|
||||
ClassDescriptor anyClass = KotlinBuiltIns.getInstance().getAny();
|
||||
FunctionDescriptor equalsFunction = getDeclaredFunctionByRawSignature(descriptor, Name.identifier("equals"), booleanClass, anyClass);
|
||||
if (equalsFunction == null) {
|
||||
if (!hasDeclaredNonTrivialMember("equals", booleanClass, anyClass)) {
|
||||
generateDataClassEqualsMethod(properties);
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDataClassEqualsMethod(List<PropertyDescriptor> properties) {
|
||||
/**
|
||||
* @return true if the class has a declared member with the given name anywhere in its hierarchy besides Any
|
||||
*/
|
||||
private boolean hasDeclaredNonTrivialMember(
|
||||
@NotNull String name,
|
||||
@NotNull ClassDescriptor returnedClassifier,
|
||||
@NotNull ClassDescriptor... valueParameterClassifiers
|
||||
) {
|
||||
FunctionDescriptor function =
|
||||
getDeclaredFunctionByRawSignature(descriptor, Name.identifier(name), returnedClassifier, valueParameterClassifiers);
|
||||
if (function == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (function.getKind() == CallableMemberDescriptor.Kind.DECLARATION) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (CallableDescriptor overridden : OverridingUtil.getOverriddenDeclarations(function)) {
|
||||
if (overridden instanceof CallableMemberDescriptor
|
||||
&& ((CallableMemberDescriptor) overridden).getKind() == CallableMemberDescriptor.Kind.DECLARATION
|
||||
&& !overridden.getContainingDeclaration().equals(KotlinBuiltIns.getInstance().getAny())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void generateDataClassEqualsMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "equals", "(Ljava/lang/Object;)Z", null, null);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
@@ -709,7 +737,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
FunctionCodegen.endVisit(mv, "equals", myClass);
|
||||
}
|
||||
|
||||
private void generateDataClassHashCodeMethod(List<PropertyDescriptor> properties) {
|
||||
private void generateDataClassHashCodeMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "hashCode", "()I", null, null);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
@@ -755,7 +783,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
||||
FunctionCodegen.endVisit(mv, "hashCode", myClass);
|
||||
}
|
||||
|
||||
private void generateDataClassToStringMethod(List<PropertyDescriptor> properties) {
|
||||
private void generateDataClassToStringMethod(@NotNull List<PropertyDescriptor> properties) {
|
||||
MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null);
|
||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||
|
||||
|
||||
+13
-1
@@ -28,9 +28,15 @@ class JavaToKotlinMethodMapGenerated {
|
||||
JavaToKotlinMethodMapGenerated() {
|
||||
ImmutableMultimap.Builder<String, JavaToKotlinMethodMap.ClassData> b = ImmutableMultimap.builder();
|
||||
|
||||
put(b, "java.lang.Object", "Any",
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int")
|
||||
);
|
||||
|
||||
put(b, "java.lang.String", "String",
|
||||
pair("compareTo(java.lang.String)", "fun compareTo(that: jet.String): jet.Int"),
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int"),
|
||||
pair("toString()", "fun toString(): jet.String")
|
||||
);
|
||||
|
||||
@@ -49,11 +55,13 @@ class JavaToKotlinMethodMapGenerated {
|
||||
);
|
||||
|
||||
put(b, "java.lang.Enum", "Enum",
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int"),
|
||||
pair("name()", "fun name(): jet.String"),
|
||||
pair("ordinal()", "fun ordinal(): jet.Int")
|
||||
);
|
||||
|
||||
put(b, "java.lang.Object", "Hashable",
|
||||
put(b, "java.lang.annotation.Annotation", "Annotation",
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int")
|
||||
);
|
||||
@@ -175,7 +183,9 @@ class JavaToKotlinMethodMapGenerated {
|
||||
pair("containsKey(java.lang.Object)", "fun containsKey(key: jet.Any?): jet.Boolean"),
|
||||
pair("containsValue(java.lang.Object)", "fun containsValue(value: jet.Any?): jet.Boolean"),
|
||||
pair("entrySet()", "fun entrySet(): jet.Set<jet.Map.Entry<K, V>>"),
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("get(java.lang.Object)", "fun get(key: jet.Any?): V?"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int"),
|
||||
pair("isEmpty()", "fun isEmpty(): jet.Boolean"),
|
||||
pair("keySet()", "fun keySet(): jet.Set<K>"),
|
||||
pair("size()", "fun size(): jet.Int"),
|
||||
@@ -187,7 +197,9 @@ class JavaToKotlinMethodMapGenerated {
|
||||
pair("containsKey(java.lang.Object)", "fun containsKey(key: jet.Any?): jet.Boolean"),
|
||||
pair("containsValue(java.lang.Object)", "fun containsValue(value: jet.Any?): jet.Boolean"),
|
||||
pair("entrySet()", "fun entrySet(): jet.MutableSet<jet.MutableMap.MutableEntry<K, V>>"),
|
||||
pair("equals(java.lang.Object)", "fun equals(other: jet.Any?): jet.Boolean"),
|
||||
pair("get(java.lang.Object)", "fun get(key: jet.Any?): V?"),
|
||||
pair("hashCode()", "fun hashCode(): jet.Int"),
|
||||
pair("isEmpty()", "fun isEmpty(): jet.Boolean"),
|
||||
pair("keySet()", "fun keySet(): jet.MutableSet<K>"),
|
||||
pair("put(K, V)", "fun put(key: K, value: V): V?"),
|
||||
|
||||
@@ -181,7 +181,7 @@ public final class ByteRange : jet.Range<jet.Byte>, jet.Progression<jet.Byte> {
|
||||
}
|
||||
}
|
||||
|
||||
public final class Char : jet.Hashable, jet.Comparable<jet.Char> {
|
||||
public final class Char : jet.Comparable<jet.Char> {
|
||||
/*primary*/ private constructor Char()
|
||||
public final fun compareTo(/*0*/ other: jet.Byte): jet.Int
|
||||
public open override /*1*/ fun compareTo(/*0*/ other: jet.Char): jet.Int
|
||||
@@ -305,7 +305,7 @@ public trait CharSequence {
|
||||
public abstract fun get(/*0*/ index: jet.Int): jet.Char
|
||||
}
|
||||
|
||||
public trait Collection</*0*/ out E> : jet.Iterable<E>, jet.Hashable {
|
||||
public trait Collection</*0*/ out E> : jet.Iterable<E> {
|
||||
public abstract fun contains(/*0*/ o: jet.Any?): jet.Boolean
|
||||
public abstract fun containsAll(/*0*/ c: jet.Collection<jet.Any?>): jet.Boolean
|
||||
public abstract fun isEmpty(): jet.Boolean
|
||||
@@ -756,9 +756,6 @@ public trait Function9</*0*/ in P1, /*1*/ in P2, /*2*/ in P3, /*3*/ in P4, /*4*/
|
||||
public abstract fun invoke(/*0*/ p1: P1, /*1*/ p2: P2, /*2*/ p3: P3, /*3*/ p4: P4, /*4*/ p5: P5, /*5*/ p6: P6, /*6*/ p7: P7, /*7*/ p8: P8, /*8*/ p9: P9): R
|
||||
}
|
||||
|
||||
public trait Hashable {
|
||||
}
|
||||
|
||||
public final enum class InlineStrategy : jet.Enum<jet.InlineStrategy> {
|
||||
/*primary*/ private constructor InlineStrategy()
|
||||
public final override /*1*/ /*fake_override*/ fun name(): jet.String
|
||||
@@ -1383,7 +1380,7 @@ public trait Map</*0*/ K, /*1*/ out V> {
|
||||
public abstract fun size(): jet.Int
|
||||
public abstract fun values(): jet.Collection<V>
|
||||
|
||||
public trait Entry</*0*/ out K, /*1*/ out V> : jet.Hashable {
|
||||
public trait Entry</*0*/ out K, /*1*/ out V> {
|
||||
public abstract fun getKey(): K
|
||||
public abstract fun getValue(): V
|
||||
}
|
||||
@@ -1463,7 +1460,7 @@ public trait MutableMap</*0*/ K, /*1*/ V> : jet.Map<K, V> {
|
||||
public abstract override /*1*/ /*fake_override*/ fun size(): jet.Int
|
||||
public abstract override /*1*/ fun values(): jet.MutableCollection<V>
|
||||
|
||||
public trait MutableEntry</*0*/ K, /*1*/ V> : jet.Map.Entry<K, V>, jet.Hashable {
|
||||
public trait MutableEntry</*0*/ K, /*1*/ V> : jet.Map.Entry<K, V> {
|
||||
public abstract override /*1*/ /*fake_override*/ fun getKey(): K
|
||||
public abstract override /*1*/ /*fake_override*/ fun getValue(): V
|
||||
public abstract fun setValue(/*0*/ value: V): V
|
||||
@@ -1488,7 +1485,7 @@ public final class Nothing {
|
||||
/*primary*/ private constructor Nothing()
|
||||
}
|
||||
|
||||
public abstract class Number : jet.Hashable {
|
||||
public abstract class Number {
|
||||
/*primary*/ public constructor Number()
|
||||
public abstract fun toByte(): jet.Byte
|
||||
public abstract fun toChar(): jet.Char
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
public class MPair<out A> (
|
||||
public val first: A
|
||||
) {
|
||||
fun equals(o: Any?): Boolean {
|
||||
override fun equals(o: Any?): Boolean {
|
||||
val t = o as MPair<*>
|
||||
return first == t.first
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ class T4(
|
||||
val c3: Boolean,
|
||||
val c4: String
|
||||
) {
|
||||
fun equals(o: Any?): Boolean {
|
||||
override fun equals(o: Any?): Boolean {
|
||||
if (o !is T4) return false;
|
||||
return c1 == o.c1 &&
|
||||
c2 == o.c2 &&
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class C(val x: Int) {
|
||||
fun equals(rhs: Any?): Boolean {
|
||||
override fun equals(rhs: Any?): Boolean {
|
||||
if (rhs is C) {
|
||||
val rhsC = rhs as C
|
||||
return rhsC.x == x
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
fun foo(): Hashable = 1
|
||||
|
||||
fun box(): String {
|
||||
if (foo() == 1) return "OK"
|
||||
return "Fail"
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
data class A(val x: Int) {
|
||||
fun equals(other: Any?): Boolean = false
|
||||
override fun equals(other: Any?): Boolean = false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ data class D(val x: Int) {
|
||||
|
||||
data class E(val x: Int) {
|
||||
fun equals(x: E): Boolean = false
|
||||
fun equals(x: Any?): Boolean = false
|
||||
override fun equals(x: Any?): Boolean = false
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Dummy {
|
||||
fun equals(other: Any?) = true
|
||||
override fun equals(other: Any?) = true
|
||||
}
|
||||
|
||||
open data class A(val v: Any)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Dummy {
|
||||
fun equals(other: Any?) = true
|
||||
override fun equals(other: Any?) = true
|
||||
}
|
||||
|
||||
data class A(val v: Any?)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
data class A(val x: Int) {
|
||||
fun hashCode(): Int = -3
|
||||
override fun hashCode(): Int = -3
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
fun box(): String {
|
||||
val a = true
|
||||
val x = if (a) {
|
||||
listOf(1)
|
||||
}
|
||||
else {
|
||||
1
|
||||
}
|
||||
// The result of the if() above is implicitly cast to jet.Hashable, which failed before we started to map Hashable to j.l.Object
|
||||
return "OK"
|
||||
}
|
||||
@@ -1,13 +1,5 @@
|
||||
class A() {
|
||||
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean = false
|
||||
}
|
||||
|
||||
class B() {
|
||||
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Boolean? = false
|
||||
}
|
||||
|
||||
class C() {
|
||||
fun equals(<!UNUSED_PARAMETER!>a<!> : Any?) : Int = 0
|
||||
override fun equals(other : Any?) : Boolean = false
|
||||
}
|
||||
|
||||
fun f(): Unit {
|
||||
@@ -22,8 +14,6 @@ fun f(): Unit {
|
||||
x != 1
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>A() == 1<!>
|
||||
B() <!RESULT_TYPE_MISMATCH!>==<!> 1
|
||||
C() <!RESULT_TYPE_MISMATCH!>==<!> 1
|
||||
|
||||
<!EQUALITY_NOT_APPLICABLE!>x === "1"<!>
|
||||
<!EQUALITY_NOT_APPLICABLE!>x !== "1"<!>
|
||||
|
||||
@@ -1 +1 @@
|
||||
fun f(a: MutableList<out Number>) = a is MutableList<out Hashable>
|
||||
fun f(a: MutableList<out Number>) = a is MutableList<out Any>
|
||||
|
||||
@@ -1 +1 @@
|
||||
fun f(a: List<Number>) = a is List<Hashable>
|
||||
fun f(a: List<Number>) = a is List<Any>
|
||||
|
||||
@@ -1 +1 @@
|
||||
fun f(a: List<Hashable>) = a is <!CANNOT_CHECK_FOR_ERASED!>List<Number><!>
|
||||
fun f(a: List<Any>) = a is <!CANNOT_CHECK_FOR_ERASED!>List<Number><!>
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Y extends X<A> {
|
||||
// FILE: test.kt
|
||||
|
||||
fun main() {
|
||||
Y().foo()<!UNSAFE_CALL!>.<!>hashCode()
|
||||
Y().foo()<!UNSAFE_CALL!>.<!>wait()
|
||||
Y().bar(null)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// No supertype at all
|
||||
class A1 {
|
||||
fun test() {
|
||||
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>.equals(null) // Call to an extension function
|
||||
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!>.identityEquals(null) // Call to an extension function
|
||||
}
|
||||
}
|
||||
@@ -50,13 +50,35 @@ Trait.traitFunc:SimpleFunctionDescriptor
|
||||
Trait.traitProp:PropertyDescriptor
|
||||
Trait:ClassDescriptorWithResolutionScopes
|
||||
a:ValueParameterDescriptor
|
||||
fake <class-object-for-Class>.equals:SimpleFunctionDescriptor
|
||||
fake <class-object-for-Class>.hashCode:SimpleFunctionDescriptor
|
||||
fake <class-object-for-NestedClass>.equals:SimpleFunctionDescriptor
|
||||
fake <class-object-for-NestedClass>.hashCode:SimpleFunctionDescriptor
|
||||
fake <class-object-for-NestedObject>.equals:SimpleFunctionDescriptor
|
||||
fake <class-object-for-NestedObject>.hashCode:SimpleFunctionDescriptor
|
||||
fake <class-object-for-NestedObject>.nestedFunc:SimpleFunctionDescriptor
|
||||
fake <class-object-for-Object>.<get-objProp>:PropertyGetterDescriptor
|
||||
fake <class-object-for-Object>.equals:SimpleFunctionDescriptor
|
||||
fake <class-object-for-Object>.hashCode:SimpleFunctionDescriptor
|
||||
fake <class-object-for-Object>.objFunc:SimpleFunctionDescriptor
|
||||
fake <class-object-for-Object>.objProp:PropertyDescriptor
|
||||
fake Class.<get-traitProp>:PropertyGetterDescriptor
|
||||
fake Class.equals:SimpleFunctionDescriptor
|
||||
fake Class.hashCode:SimpleFunctionDescriptor
|
||||
fake Class.traitFunc:SimpleFunctionDescriptor
|
||||
fake Class.traitProp:PropertyDescriptor
|
||||
fake NestedClass.equals:SimpleFunctionDescriptor
|
||||
fake NestedClass.hashCode:SimpleFunctionDescriptor
|
||||
fake NestedObject.equals:SimpleFunctionDescriptor
|
||||
fake NestedObject.hashCode:SimpleFunctionDescriptor
|
||||
fake NestedTrait.equals:SimpleFunctionDescriptor
|
||||
fake NestedTrait.hashCode:SimpleFunctionDescriptor
|
||||
fake Object.equals:SimpleFunctionDescriptor
|
||||
fake Object.hashCode:SimpleFunctionDescriptor
|
||||
fake Outer.equals:SimpleFunctionDescriptor
|
||||
fake Outer.hashCode:SimpleFunctionDescriptor
|
||||
fake Trait.equals:SimpleFunctionDescriptor
|
||||
fake Trait.hashCode:SimpleFunctionDescriptor
|
||||
func.this:ReceiverParameterDescriptor
|
||||
innerTest.<get-prop>:PropertyGetterDescriptor
|
||||
innerTest.<get-propVar>:PropertyGetterDescriptor
|
||||
@@ -65,6 +87,17 @@ innerTest.func:SimpleFunctionDescriptor
|
||||
innerTest.prop:PropertyDescriptor
|
||||
innerTest.propVar:PropertyDescriptor
|
||||
innerTest:PackageViewDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
other:ValueParameterDescriptor
|
||||
prop.this:ReceiverParameterDescriptor
|
||||
prop.this:ReceiverParameterDescriptor
|
||||
test:PackageViewDescriptor
|
||||
@@ -5106,11 +5106,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/typeMapping"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("hashable.kt")
|
||||
public void testHashable() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/typeMapping/hashable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt2831.kt")
|
||||
public void testKt2831() throws Exception {
|
||||
doTest("compiler/testData/codegen/box/typeMapping/kt2831.kt");
|
||||
|
||||
-5
@@ -908,11 +908,6 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/getGenericInterfaces.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implicitlyCastToHashable.kt")
|
||||
public void testImplicitlyCastToHashable() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/implicitlyCastToHashable.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1406.kt")
|
||||
public void testKt1406() throws Exception {
|
||||
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/regressions/kt1406.kt");
|
||||
|
||||
@@ -150,7 +150,7 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
assertType("if (true) 1 else null", "Int?");
|
||||
assertType("if (true) null else null", "Nothing?");
|
||||
|
||||
assertType("if (true) 1 else '1'", "Any");
|
||||
assertType("if (true) 1 else '1'", "Comparable<out Any?>");
|
||||
|
||||
assertType("if (true) else '1'", "Unit");
|
||||
assertType("if (true) else { var a = 0; a = 1 }", "Unit");
|
||||
@@ -158,19 +158,19 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
|
||||
public void testWhen() throws Exception {
|
||||
assertType("when (1) { is 1 -> 2; } ", "Int");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'} ", "Any");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> null} ", "Any?");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; else -> null} ", "Any?");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> when(2) {is 1 -> null}} ", "Any?");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'} ", "Comparable<out Any?>");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> null} ", "Comparable<out Any?>?");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; else -> null} ", "Comparable<out Any?>?");
|
||||
assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> when(2) {is 1 -> null}} ", "Comparable<out Any?>?");
|
||||
}
|
||||
|
||||
public void testTry() throws Exception {
|
||||
assertType("try {1} finally{2}", "Int");
|
||||
assertType("try {1} catch (e : Exception) {'a'} finally{2}", "Any");
|
||||
assertType("try {1} catch (e : Exception) {'a'} finally{2}", "Comparable<out Any?>");
|
||||
assertType("try {1} catch (e : Exception) {2} finally{'a'}", "Int");
|
||||
assertType("try {1} catch (e : Exception) {'a'} finally{'2'}", "Any");
|
||||
assertType("try {1} catch (e : Exception) {'a'}", "Any");
|
||||
assertType("try {1} catch (e : Exception) {'a'} catch (e : Exception) {null}", "Any?");
|
||||
assertType("try {1} catch (e : Exception) {'a'} finally{'2'}", "Comparable<out Any?>");
|
||||
assertType("try {1} catch (e : Exception) {'a'}", "Comparable<out Any?>");
|
||||
assertType("try {1} catch (e : Exception) {'a'} catch (e : Exception) {null}", "Comparable<out Any?>?");
|
||||
assertType("try {} catch (e : Exception) {}", "Unit");
|
||||
}
|
||||
|
||||
@@ -184,7 +184,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
assertCommonSupertype("Int?", "Int", "Nothing?");
|
||||
assertCommonSupertype("Nothing?", "Nothing?", "Nothing?");
|
||||
|
||||
assertCommonSupertype("Any", "Int", "Char");
|
||||
assertCommonSupertype("Any", "Char", "Number");
|
||||
assertCommonSupertype("Comparable<out Any?>", "Int", "Char");
|
||||
|
||||
assertCommonSupertype("Base_T<*>", "Base_T<*>", "Derived_T<*>");
|
||||
assertCommonSupertype("Any", "Base_inT<*>", "Derived_T<*>");
|
||||
@@ -200,9 +201,9 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
}
|
||||
|
||||
public void testIntersect() throws Exception {
|
||||
assertIntersection("Number", "Number?", "Hashable");
|
||||
assertIntersection("Number", "Hashable", "Number?");
|
||||
assertIntersection("Hashable", "Hashable?", "Hashable");
|
||||
assertIntersection("Long", "Long?", "Number");
|
||||
assertIntersection("Long", "Number", "Long?");
|
||||
assertIntersection("Number", "Number?", "Number");
|
||||
|
||||
assertIntersection("Int?", "Int?", "Int?");
|
||||
assertIntersection("Int", "Int?", "Int");
|
||||
|
||||
Reference in New Issue
Block a user