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");
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
package jet
|
||||
|
||||
public open class Any() {}
|
||||
public open class Any {
|
||||
public open fun equals(other: Any?): Boolean
|
||||
|
||||
public open fun hashCode(): Int
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jet
|
||||
|
||||
public class Char private () : Hashable, Comparable<Char> {
|
||||
public class Char private () : Comparable<Char> {
|
||||
public fun compareTo(other : Double) : Int
|
||||
public fun compareTo(other : Float) : Int
|
||||
public fun compareTo(other : Long) : Int
|
||||
@@ -63,7 +63,4 @@ public class Char private () : Hashable, Comparable<Char> {
|
||||
public fun toChar() : Char
|
||||
public fun toShort() : Short
|
||||
public fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ public trait MutableIterable<out T> : Iterable<T> {
|
||||
override fun iterator() : MutableIterator<T>
|
||||
}
|
||||
|
||||
public trait Collection<out E> : Iterable<E>, Hashable {
|
||||
public trait Collection<out E> : Iterable<E> {
|
||||
// Query Operations
|
||||
public fun size() : Int
|
||||
public fun isEmpty() : Boolean
|
||||
@@ -123,7 +123,7 @@ public trait Map<K, out V> {
|
||||
public fun values() : Collection<V>
|
||||
public fun entrySet() : Set<Map.Entry<K, V>>
|
||||
|
||||
public trait Entry<out K, out V> : Hashable {
|
||||
public trait Entry<out K, out V> {
|
||||
public fun getKey() : K
|
||||
public fun getValue() : V
|
||||
}
|
||||
@@ -143,7 +143,7 @@ public trait MutableMap<K, V> : Map<K, V> {
|
||||
override fun values() : MutableCollection<V>
|
||||
override fun entrySet() : MutableSet<MutableMap.MutableEntry<K, V>>
|
||||
|
||||
public trait MutableEntry<K,V> : Map.Entry<K, V>, Hashable {
|
||||
public trait MutableEntry<K,V> : Map.Entry<K, V> {
|
||||
public fun setValue(value : V) : V
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,27 +4,21 @@ public trait Annotation
|
||||
|
||||
public annotation class volatile
|
||||
|
||||
public fun <R> synchronized(lock: Any, block : () -> R) : R
|
||||
public fun <R> synchronized(lock: Any, block: () -> R): R
|
||||
|
||||
public fun Any?.identityEquals(other : Any?) : Boolean // = this === other
|
||||
public fun Any?.identityEquals(other: Any?): Boolean // = this === other
|
||||
|
||||
// Can't write a body due to a bootstrapping problem (see JET-74)
|
||||
public fun Any?.equals(other : Any?) : Boolean// = this === other
|
||||
public fun Any?.equals(other: Any?): Boolean
|
||||
|
||||
// Returns "null" for null
|
||||
public fun Any?.toString() : String// = this === other
|
||||
public fun Any?.toString(): String
|
||||
|
||||
public fun String?.plus(other: Any?) : String
|
||||
public fun String?.plus(other: Any?): String
|
||||
|
||||
public trait Comparable<in T> {
|
||||
public fun compareTo(other : T) : Int
|
||||
}
|
||||
|
||||
public trait Hashable {
|
||||
public fun hashCode() : Int
|
||||
public fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Boolean private () : Comparable<Boolean> {
|
||||
public fun not() : Boolean
|
||||
|
||||
@@ -35,8 +29,6 @@ public class Boolean private () : Comparable<Boolean> {
|
||||
public fun xor(other : Boolean) : Boolean
|
||||
|
||||
public override fun compareTo(other : Boolean) : Int
|
||||
|
||||
public fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public trait CharSequence {
|
||||
@@ -50,8 +42,6 @@ public trait CharSequence {
|
||||
public class String() : Comparable<String>, CharSequence {
|
||||
public fun plus(other : Any?) : String
|
||||
|
||||
public fun equals(other : Any?) : Boolean
|
||||
|
||||
public override fun compareTo(that : String) : Int
|
||||
public override fun get(index : Int) : Char
|
||||
public override fun toString() : String
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package jet
|
||||
|
||||
public abstract class Number : Hashable {
|
||||
public abstract class Number {
|
||||
public abstract fun toDouble() : Double
|
||||
public abstract fun toFloat() : Float
|
||||
public abstract fun toLong() : Long
|
||||
@@ -8,13 +8,6 @@ public abstract class Number : Hashable {
|
||||
public abstract fun toChar() : Char
|
||||
public abstract fun toShort() : Short
|
||||
public abstract fun toByte() : Byte
|
||||
// fun equals(other : Double) : Boolean
|
||||
// fun equals(other : Float) : Boolean
|
||||
// fun equals(other : Long) : Boolean
|
||||
// fun equals(other : Byte) : Boolean
|
||||
// fun equals(other : Int) : Boolean
|
||||
// fun equals(other : Short) : Boolean
|
||||
// fun equals(other : Char) : Boolean
|
||||
}
|
||||
|
||||
public class Double private () : Number, Comparable<Double> {
|
||||
@@ -85,9 +78,6 @@ public class Double private () : Number, Comparable<Double> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Float private () : Number, Comparable<Float> {
|
||||
@@ -159,9 +149,6 @@ public class Float private () : Number, Comparable<Float> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Long private () : Number, Comparable<Long> {
|
||||
@@ -241,9 +228,6 @@ public class Long private () : Number, Comparable<Long> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Int private () : Number, Comparable<Int> {
|
||||
@@ -323,9 +307,6 @@ public class Int private () : Number, Comparable<Int> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Short private () : Number, Comparable<Short> {
|
||||
@@ -397,9 +378,6 @@ public class Short private () : Number, Comparable<Short> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Byte private () : Number, Comparable<Byte> {
|
||||
@@ -471,7 +449,4 @@ public class Byte private () : Number, Comparable<Byte> {
|
||||
public override fun toChar() : Char
|
||||
public override fun toShort() : Short
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
@@ -29,10 +29,10 @@ public class ByteProgression(
|
||||
|
||||
override fun iterator(): ByteIterator = ByteProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ByteProgression && start == other.start && end == other.end && increment == other.increment
|
||||
|
||||
fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
override fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -48,10 +48,10 @@ public class CharProgression(
|
||||
|
||||
override fun iterator(): CharIterator = CharProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is CharProgression && start == other.start && end == other.end && increment == other.increment
|
||||
|
||||
fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
override fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -67,10 +67,10 @@ public class ShortProgression(
|
||||
|
||||
override fun iterator(): ShortIterator = ShortProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ShortProgression && start == other.start && end == other.end && increment == other.increment
|
||||
|
||||
fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
override fun hashCode(): Int = 31 * (31 * start.toInt() + end) + increment
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -86,10 +86,10 @@ public class IntProgression(
|
||||
|
||||
override fun iterator(): IntIterator = IntProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is IntProgression && start == other.start && end == other.end && increment == other.increment
|
||||
|
||||
fun hashCode(): Int = 31 * (31 * start + end) + increment
|
||||
override fun hashCode(): Int = 31 * (31 * start + end) + increment
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -105,10 +105,10 @@ public class LongProgression(
|
||||
|
||||
override fun iterator(): LongIterator = LongProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is LongProgression && start == other.start && end == other.end && increment == other.increment
|
||||
|
||||
fun hashCode(): Int = (31 * (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))) + (increment xor (increment ushr 32))).toInt()
|
||||
override fun hashCode(): Int = (31 * (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))) + (increment xor (increment ushr 32))).toInt()
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -125,10 +125,10 @@ public class FloatProgression(
|
||||
|
||||
override fun iterator(): FloatIterator = FloatProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is FloatProgression && java.lang.Float.compare(start, other.start) == 0 && java.lang.Float.compare(end, other.end) == 0 && java.lang.Float.compare(increment, other.increment) == 0
|
||||
|
||||
fun hashCode(): Int = 31 * (31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(end)) + java.lang.Float.floatToIntBits(increment)
|
||||
override fun hashCode(): Int = 31 * (31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(end)) + java.lang.Float.floatToIntBits(increment)
|
||||
|
||||
fun toString(): String = if (increment > 0) "$start..$end step $increment" else "$start downTo $end step ${-increment}"
|
||||
}
|
||||
@@ -145,10 +145,10 @@ public class DoubleProgression(
|
||||
|
||||
override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is DoubleProgression && java.lang.Double.compare(start, other.start) == 0 && java.lang.Double.compare(end, other.end) == 0 && java.lang.Double.compare(increment, other.increment) == 0
|
||||
|
||||
fun hashCode(): Int {
|
||||
override fun hashCode(): Int {
|
||||
var temp = java.lang.Double.doubleToLongBits(start)
|
||||
var result = (temp xor (temp ushr 32))
|
||||
temp = java.lang.Double.doubleToLongBits(end)
|
||||
|
||||
@@ -26,10 +26,10 @@ public class ByteRange(public override val start: Byte, public override val end:
|
||||
|
||||
override fun iterator(): ByteIterator = ByteProgressionIterator(start, end, 1)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ByteRange && start == other.start && end == other.end
|
||||
|
||||
fun hashCode(): Int = 31 * start.toInt() + end
|
||||
override fun hashCode(): Int = 31 * start.toInt() + end
|
||||
|
||||
class object {
|
||||
public val EMPTY: ByteRange = ByteRange(1, 0)
|
||||
@@ -44,10 +44,10 @@ public class CharRange(public override val start: Char, public override val end:
|
||||
|
||||
override fun iterator(): CharIterator = CharProgressionIterator(start, end, 1)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is CharRange && start == other.start && end == other.end
|
||||
|
||||
fun hashCode(): Int = 31 * start.toInt() + end
|
||||
override fun hashCode(): Int = 31 * start.toInt() + end
|
||||
|
||||
class object {
|
||||
public val EMPTY: CharRange = CharRange(1.toChar(), 0.toChar())
|
||||
@@ -62,10 +62,10 @@ public class ShortRange(public override val start: Short, public override val en
|
||||
|
||||
override fun iterator(): ShortIterator = ShortProgressionIterator(start, end, 1)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is ShortRange && start == other.start && end == other.end
|
||||
|
||||
fun hashCode(): Int = 31 * start.toInt() + end
|
||||
override fun hashCode(): Int = 31 * start.toInt() + end
|
||||
|
||||
class object {
|
||||
public val EMPTY: ShortRange = ShortRange(1, 0)
|
||||
@@ -80,10 +80,10 @@ public class IntRange(public override val start: Int, public override val end: I
|
||||
|
||||
override fun iterator(): IntIterator = IntProgressionIterator(start, end, 1)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is IntRange && start == other.start && end == other.end
|
||||
|
||||
fun hashCode(): Int = 31 * start + end
|
||||
override fun hashCode(): Int = 31 * start + end
|
||||
|
||||
class object {
|
||||
public val EMPTY: IntRange = IntRange(1, 0)
|
||||
@@ -98,10 +98,10 @@ public class LongRange(public override val start: Long, public override val end:
|
||||
|
||||
override fun iterator(): LongIterator = LongProgressionIterator(start, end, 1)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is LongRange && start == other.start && end == other.end
|
||||
|
||||
fun hashCode(): Int = (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))).toInt()
|
||||
override fun hashCode(): Int = (31 * (start xor (start ushr 32)) + (end xor (end ushr 32))).toInt()
|
||||
|
||||
class object {
|
||||
public val EMPTY: LongRange = LongRange(1, 0)
|
||||
@@ -116,10 +116,10 @@ public class FloatRange(public override val start: Float, public override val en
|
||||
|
||||
override fun iterator(): FloatIterator = FloatProgressionIterator(start, end, 1.0f)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is FloatRange && java.lang.Float.compare(start, other.start) == 0 && java.lang.Float.compare(end, other.end) == 0
|
||||
|
||||
fun hashCode(): Int = 31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(end)
|
||||
override fun hashCode(): Int = 31 * java.lang.Float.floatToIntBits(start) + java.lang.Float.floatToIntBits(end)
|
||||
|
||||
class object {
|
||||
public val EMPTY: FloatRange = FloatRange(1.0f, 0.0f)
|
||||
@@ -134,10 +134,10 @@ public class DoubleRange(public override val start: Double, public override val
|
||||
|
||||
override fun iterator(): DoubleIterator = DoubleProgressionIterator(start, end, 1.0)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is DoubleRange && java.lang.Double.compare(start, other.start) == 0 && java.lang.Double.compare(end, other.end) == 0
|
||||
|
||||
fun hashCode(): Int {
|
||||
override fun hashCode(): Int {
|
||||
var temp = java.lang.Double.doubleToLongBits(start)
|
||||
val result = (temp xor (temp ushr 32))
|
||||
temp = java.lang.Double.doubleToLongBits(end)
|
||||
|
||||
-1
@@ -43,7 +43,6 @@ public abstract class JavaToKotlinClassMapBuilder {
|
||||
register(Enum.class, kotlinBuiltIns.getEnum());
|
||||
register(Annotation.class, kotlinBuiltIns.getAnnotation());
|
||||
register(Deprecated.class, kotlinBuiltIns.getDeprecatedAnnotation(), Direction.JAVA_TO_KOTLIN);
|
||||
register(Object.class, kotlinBuiltIns.getHashable(), Direction.KOTLIN_TO_JAVA);
|
||||
register(Void.class, kotlinBuiltIns.getNothing(), Direction.KOTLIN_TO_JAVA);
|
||||
|
||||
register(Iterable.class, kotlinBuiltIns.getIterable(), kotlinBuiltIns.getMutableIterable());
|
||||
|
||||
@@ -51,12 +51,11 @@ public class SubstitutionUtils {
|
||||
For each supertype of a given type, we map type parameters to type arguments.
|
||||
|
||||
For instance, we have the following class hierarchy:
|
||||
trait Hashable
|
||||
trait Iterable<out T>
|
||||
trait Collection<out E>: Iterable<E>, Hashable
|
||||
trait Collection<out E>: Iterable<E>
|
||||
trait MyFooCollection<F>: Collection<Foo<F>>
|
||||
|
||||
For MyFunCollection<out CharSequence>, the following multimap will be returned:
|
||||
For MyFooCollection<out CharSequence>, the following multimap will be returned:
|
||||
T declared in Iterable -> Foo<out CharSequence>
|
||||
E declared in Collection -> Foo<out CharSequence>
|
||||
F declared in MyFooCollection -> out CharSequence
|
||||
|
||||
@@ -307,11 +307,6 @@ public class KotlinBuiltIns {
|
||||
return getBuiltInClassByName("Number");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getHashable() {
|
||||
return getBuiltInClassByName("Hashable");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getUnit() {
|
||||
return getBuiltInClassByName("Unit");
|
||||
@@ -514,7 +509,6 @@ public class KotlinBuiltIns {
|
||||
getString(),
|
||||
getCharSequence(),
|
||||
getThrowable(),
|
||||
getBuiltInClassByName("Hashable"),
|
||||
|
||||
getIterator(),
|
||||
getIterable(),
|
||||
|
||||
@@ -71,10 +71,10 @@ class GenerateProgressions(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
|
||||
override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(start, end, increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is $progression && ${compare("start")} && ${compare("end")} && ${compare("increment")}
|
||||
|
||||
fun hashCode(): Int $hashCode
|
||||
override fun hashCode(): Int $hashCode
|
||||
|
||||
fun toString(): String = ${"if (increment > 0) \"\$start..\$end step \$increment\" else \"\$start downTo \$end step \${-increment}\""}
|
||||
}""")
|
||||
|
||||
@@ -66,10 +66,10 @@ class GenerateRanges(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
|
||||
override fun iterator(): ${t}Iterator = ${t}ProgressionIterator(start, end, $increment)
|
||||
|
||||
fun equals(other: Any?): Boolean =
|
||||
override fun equals(other: Any?): Boolean =
|
||||
other is $range && ${compare("start")} && ${compare("end")}
|
||||
|
||||
fun hashCode(): Int $hashCode
|
||||
override fun hashCode(): Int $hashCode
|
||||
|
||||
class object {
|
||||
public val EMPTY: $range = $range($emptyBounds)
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
class A() {
|
||||
fun equals(<warning>a</warning> : Any?) : Boolean = false
|
||||
}
|
||||
|
||||
class B() {
|
||||
fun equals(<warning>a</warning> : Any?) : Boolean? = false
|
||||
}
|
||||
|
||||
class C() {
|
||||
fun equals(<warning>a</warning> : Any?) : Int = 0
|
||||
override fun equals(<warning>a</warning> : Any?) : Boolean = false
|
||||
}
|
||||
|
||||
fun f(): Unit {
|
||||
@@ -22,8 +14,6 @@ fun f(): Unit {
|
||||
x != 1
|
||||
|
||||
<error>A() == 1</error>
|
||||
B() <error>==</error> 1
|
||||
C() <error>==</error> 1
|
||||
|
||||
<error>x === "1"</error>
|
||||
<error>x !== "1"</error>
|
||||
|
||||
@@ -4,6 +4,5 @@ class Test {
|
||||
}
|
||||
}
|
||||
|
||||
// EXIST: Any, Nothing, Unit, Int, Number
|
||||
// EXIST: Array, Hashable
|
||||
// EXIST: Any, Nothing, Unit, Int, Number, Array
|
||||
// EXIST_JAVA_ONLY: Math, Thread
|
||||
@@ -3,6 +3,5 @@ class Test : <caret> {
|
||||
}
|
||||
}
|
||||
|
||||
// EXIST: Any, Nothing, Unit, Int, Number
|
||||
// EXIST: Array, Hashable
|
||||
// EXIST: Any, Nothing, Unit, Int, Number, Array
|
||||
// EXIST_JAVA_ONLY: Math, Thread
|
||||
@@ -13,8 +13,7 @@ deprecated("Use A instead") fun MyClass.contains(i: MyClass): Boolean { i.i; ret
|
||||
|
||||
deprecated("Use A instead") fun MyClass.plusAssign(i: MyClass) { i.i }
|
||||
|
||||
deprecated("Use A instead") fun MyClass.equals(i: Any?): Boolean { i == null; return false }
|
||||
deprecated("Use A instead") fun MyClass.compareTo(i: MyClass): Int { return i.i }
|
||||
deprecated("Use A instead") fun MyClass.rangeTo(i: MyClass): IntRange { return IntRange(i.i, i.i) }
|
||||
|
||||
fun test() {
|
||||
val x1 = MyClass()
|
||||
@@ -32,9 +31,7 @@ fun test() {
|
||||
|
||||
x1 <warning descr="'fun plusAssign(i: MyClass)' is deprecated. Use A instead">+=</warning> x2
|
||||
|
||||
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">==</warning> x2
|
||||
x1 <warning descr="'fun equals(i: jet.Any?)' is deprecated. Use A instead">!=</warning> x2
|
||||
x1 <warning descr="'fun compareTo(i: MyClass)' is deprecated. Use A instead">></warning> x2
|
||||
x1<warning descr="'fun rangeTo(i: MyClass)' is deprecated. Use A instead">..</warning>x2
|
||||
}
|
||||
|
||||
// NO_CHECK_INFOS
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// "class org.jetbrains.jet.plugin.quickfix.AddFunctionParametersFix" "false"
|
||||
// ERROR: Too many arguments for public fun jet.Any?.equals(other: jet.Any?): jet.Boolean defined in jet
|
||||
// ERROR: Too many arguments for public open fun equals(other: jet.Any?): jet.Boolean defined in jet.Any
|
||||
|
||||
fun f(d: Any) {
|
||||
d.equals("a", <caret>"b")
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
val x = 5.<ref>equals(5)
|
||||
//jet/Numbers.kt:equals
|
||||
//jet/Any.kt:equals
|
||||
|
||||
@@ -6,12 +6,12 @@ class T4(
|
||||
val c3: Boolean,
|
||||
val c4: String
|
||||
) {
|
||||
fun equals(o: Any?): Boolean {
|
||||
if (o !is T4) return false;
|
||||
return c1 == o.c1 &&
|
||||
c2 == o.c2 &&
|
||||
c3 == o.c3 &&
|
||||
c4 == o.c4
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is T4) return false;
|
||||
return c1 == other.c1 &&
|
||||
c2 == other.c2 &&
|
||||
c3 == other.c3 &&
|
||||
c4 == other.c4
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
public fun equals(that: Any?): Boolean {
|
||||
if (that !is Foo) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == that.name
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
public fun equals(that: Any?): Boolean {
|
||||
if (that !is Foo) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == that.name
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package foo
|
||||
|
||||
class Foo(val name: String) {
|
||||
public fun equals(that: Any?): Boolean {
|
||||
if (that !is Foo) {
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (other !is Foo) {
|
||||
return false
|
||||
}
|
||||
return this.name == that.name
|
||||
return this.name == other.name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ public fun equals(a: Any?): Boolean = true
|
||||
public fun hashCode(): Int = 0
|
||||
public fun toString(): String = ""
|
||||
|
||||
public class PublicClassWithPublics {
|
||||
public fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
public fun hashCode(): Int = 0
|
||||
public class PublicClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 0
|
||||
public fun toString(): String = "PublicClass"
|
||||
}
|
||||
|
||||
class InternalClassWithPublics {
|
||||
public fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
public fun hashCode(): Int = 1
|
||||
internal class InternalClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 1
|
||||
public fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
@@ -21,9 +21,9 @@ class InternalClassWithPublics {
|
||||
public fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
private class PrivateClassWithPublics {
|
||||
public fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
public fun hashCode(): Int = 2
|
||||
private class PrivateClass {
|
||||
override fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
override fun hashCode(): Int = 2
|
||||
public fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
@@ -32,126 +32,6 @@ private class PrivateClassWithPublics {
|
||||
public fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
public class PublicClassWithProtecteds {
|
||||
protected fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
protected fun hashCode(): Int = 0
|
||||
protected fun toString(): String = "public Bar"
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
}
|
||||
|
||||
class InternalClassWithProtecteds {
|
||||
protected fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
protected fun hashCode(): Int = 1
|
||||
protected fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
protected fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
protected fun hashCode(i: Int): Int = i
|
||||
protected fun toString(s: String): String = s
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
val call_equals2: ()->Unit = { equals(0, 1) }
|
||||
val call_hashCode2: ()->Unit = { hashCode(2) }
|
||||
val call_toString2: ()->Unit = { toString("3") }
|
||||
}
|
||||
|
||||
private class PrivateClassWithProtecteds {
|
||||
protected fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
protected fun hashCode(): Int = 2
|
||||
protected fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
protected fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
protected fun hashCode(i: Int): Int = i
|
||||
protected fun toString(s: String): String = s
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
val call_equals2: ()->Unit = { equals(0, 1) }
|
||||
val call_hashCode2: ()->Unit = { hashCode(2) }
|
||||
val call_toString2: ()->Unit = { toString("3") }
|
||||
}
|
||||
|
||||
public class PublicClassWithInternals {
|
||||
fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
fun hashCode(): Int = 0
|
||||
fun toString(): String = "public Bar"
|
||||
}
|
||||
|
||||
class InternalClassWithInternals {
|
||||
fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
fun hashCode(): Int = 1
|
||||
fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
fun hashCode(i: Int): Int = i
|
||||
fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
private class PrivateClassWithInternals {
|
||||
fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
fun hashCode(): Int = 2
|
||||
fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
fun hashCode(i: Int): Int = i
|
||||
fun toString(s: String): String = s
|
||||
}
|
||||
|
||||
public class PublicClassWithPrivates {
|
||||
private fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
private fun hashCode(): Int = 0
|
||||
private fun toString(): String = "public Bar"
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
}
|
||||
|
||||
class InternalClassWithPrivates {
|
||||
private fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
private fun hashCode(): Int = 1
|
||||
private fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
private fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
private fun hashCode(i: Int): Int = i
|
||||
private fun toString(s: String): String = s
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
val call_equals2: ()->Unit = { equals(0, 1) }
|
||||
val call_hashCode2: ()->Unit = { hashCode(2) }
|
||||
val call_toString2: ()->Unit = { toString("3") }
|
||||
}
|
||||
|
||||
private class PrivateClassWithPrivates {
|
||||
private fun equals(a: Any?): Boolean = this.identityEquals(a)
|
||||
private fun hashCode(): Int = 2
|
||||
private fun toString(): String = "InternalClass"
|
||||
|
||||
// overloads
|
||||
private fun equals(a: Any?, b: Any?): Boolean = a == b
|
||||
private fun hashCode(i: Int): Int = i
|
||||
private fun toString(s: String): String = s
|
||||
|
||||
val call_equals: ()->Unit = { equals(0) }
|
||||
val call_hashCode: ()->Unit = { hashCode() }
|
||||
val call_toString: ()->Unit = { toString() }
|
||||
val call_equals2: ()->Unit = { equals(0, 1) }
|
||||
val call_hashCode2: ()->Unit = { hashCode(2) }
|
||||
val call_toString2: ()->Unit = { toString("3") }
|
||||
}
|
||||
|
||||
// Helpers
|
||||
|
||||
native
|
||||
@@ -194,89 +74,26 @@ val STABLE_HASH_CODE = { hashCode()}.extractNames()[1]
|
||||
val STABLE_TO_STRING = { toString()}.extractNames()[1]
|
||||
|
||||
fun box(): String {
|
||||
testGroup = "Public Class with publics"
|
||||
test(STABLE_EQUALS) { PublicClassWithPublics().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PublicClassWithPublics().hashCode() }
|
||||
test(STABLE_TO_STRING) { PublicClassWithPublics().toString() }
|
||||
testGroup = "Public Class"
|
||||
test(STABLE_EQUALS) { PublicClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PublicClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { PublicClass().toString() }
|
||||
|
||||
testGroup = "Internal Class with publics"
|
||||
test(STABLE_EQUALS) { InternalClassWithPublics().equals(0) }
|
||||
test(STABLE_HASH_CODE) { InternalClassWithPublics().hashCode() }
|
||||
test(STABLE_TO_STRING) { InternalClassWithPublics().toString() }
|
||||
testGroup = "Internal Class"
|
||||
test(STABLE_EQUALS) { InternalClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { InternalClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { InternalClass().toString() }
|
||||
//test(SIMPLE_EQUALS) { InternalClassWithPublics().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { InternalClassWithPublics().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { InternalClassWithPublics().toString("3") }
|
||||
|
||||
testGroup = "Private Class with publics"
|
||||
test(STABLE_EQUALS) { PrivateClassWithPublics().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PrivateClassWithPublics().hashCode() }
|
||||
test(STABLE_TO_STRING) { PrivateClassWithPublics().toString() }
|
||||
testGroup = "Private Class"
|
||||
test(STABLE_EQUALS) { PrivateClass().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PrivateClass().hashCode() }
|
||||
test(STABLE_TO_STRING) { PrivateClass().toString() }
|
||||
//test(SIMPLE_EQUALS) { PrivateClassWithPublics().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { PrivateClassWithPublics().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { PrivateClassWithPublics().toString("3") }
|
||||
|
||||
testGroup = "Public Class with protecteds"
|
||||
test(STABLE_EQUALS, PublicClassWithProtecteds().call_equals)
|
||||
test(STABLE_HASH_CODE, PublicClassWithProtecteds().call_hashCode)
|
||||
test(STABLE_TO_STRING, PublicClassWithProtecteds().call_toString)
|
||||
|
||||
testGroup = "Internal Class with protecteds"
|
||||
test(STABLE_EQUALS, InternalClassWithProtecteds().call_equals)
|
||||
test(STABLE_HASH_CODE, InternalClassWithProtecteds().call_hashCode)
|
||||
test(STABLE_TO_STRING, InternalClassWithProtecteds().call_toString)
|
||||
//test(SIMPLE_EQUALS, InternalClassWithProtecteds().call_equals2)
|
||||
//test(SIMPLE_HASH_CODE, InternalClassWithProtecteds().call_hashCode2)
|
||||
//test(SIMPLE_TO_STRING, InternalClassWithProtecteds().call_toString2)
|
||||
|
||||
testGroup = "Private Class with protecteds"
|
||||
test(STABLE_EQUALS, PrivateClassWithProtecteds().call_equals)
|
||||
test(STABLE_HASH_CODE, PrivateClassWithProtecteds().call_hashCode)
|
||||
test(STABLE_TO_STRING, PrivateClassWithProtecteds().call_toString)
|
||||
//test(STABLE_EQUALS_OVERLOAD, PrivateClassWithProtecteds().call_equals2)
|
||||
//test(STABLE_HASH_CODE_OVERLOAD, PrivateClassWithProtecteds().call_hashCode2)
|
||||
//test(STABLE_TO_STRING_OVERLOAD, PrivateClassWithProtecteds().call_toString2)
|
||||
|
||||
testGroup = "Public Class with internals"
|
||||
test(STABLE_EQUALS) { PublicClassWithInternals().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PublicClassWithInternals().hashCode() }
|
||||
test(STABLE_TO_STRING) { PublicClassWithInternals().toString() }
|
||||
|
||||
testGroup = "Internal Class with internals"
|
||||
test(STABLE_EQUALS) { InternalClassWithInternals().equals(0) }
|
||||
test(STABLE_HASH_CODE) { InternalClassWithInternals().hashCode() }
|
||||
test(STABLE_TO_STRING) { InternalClassWithInternals().toString() }
|
||||
//test(SIMPLE_EQUALS) { InternalClassWithInternals().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { InternalClassWithInternals().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { InternalClassWithInternals().toString("3") }
|
||||
|
||||
testGroup = "Private Class with internals"
|
||||
test(STABLE_EQUALS) { PrivateClassWithInternals().equals(0) }
|
||||
test(STABLE_HASH_CODE) { PrivateClassWithInternals().hashCode() }
|
||||
test(STABLE_TO_STRING) { PrivateClassWithInternals().toString() }
|
||||
//test(SIMPLE_EQUALS) { PrivateClassWithInternals().equals(0, 1) }
|
||||
//test(SIMPLE_HASH_CODE) { PrivateClassWithInternals().hashCode(2) }
|
||||
//test(SIMPLE_TO_STRING) { PrivateClassWithInternals().toString("3") }
|
||||
|
||||
testGroup = "Public Class with privates"
|
||||
test(STABLE_EQUALS, PublicClassWithPrivates().call_equals)
|
||||
test(STABLE_HASH_CODE, PublicClassWithPrivates().call_hashCode)
|
||||
test(STABLE_TO_STRING, PublicClassWithPrivates().call_toString)
|
||||
|
||||
testGroup = "Internal Class with privates"
|
||||
test(STABLE_EQUALS, InternalClassWithPrivates().call_equals)
|
||||
test(STABLE_HASH_CODE, InternalClassWithPrivates().call_hashCode)
|
||||
test(STABLE_TO_STRING, InternalClassWithPrivates().call_toString)
|
||||
//test(SIMPLE_EQUALS, InternalClassWithPrivates().call_equals2)
|
||||
//test(SIMPLE_HASH_CODE, InternalClassWithPrivates().call_hashCode2)
|
||||
//test(SIMPLE_TO_STRING, InternalClassWithPrivates().call_toString2)
|
||||
|
||||
testGroup = "Private Class with privates"
|
||||
test(STABLE_EQUALS, PrivateClassWithPrivates().call_equals)
|
||||
test(STABLE_HASH_CODE, PrivateClassWithPrivates().call_hashCode)
|
||||
test(STABLE_TO_STRING, PrivateClassWithPrivates().call_toString)
|
||||
//test(SIMPLE_EQUALS, PrivateClassWithPrivates().call_equals2)
|
||||
//test(SIMPLE_HASH_CODE, PrivateClassWithPrivates().call_hashCode2)
|
||||
//test(SIMPLE_TO_STRING, PrivateClassWithPrivates().call_toString2)
|
||||
|
||||
return "OK"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user