diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java index 5d68268a7db..c0a53ab8301 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ImplementationBodyCodegen.java @@ -632,30 +632,58 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen { } } - private void generateDataClassToStringIfNeeded(List properties) { + private void generateDataClassToStringIfNeeded(@NotNull List properties) { ClassDescriptor stringClass = KotlinBuiltIns.getInstance().getString(); - if (getDeclaredFunctionByRawSignature(descriptor, Name.identifier("toString"), stringClass) == null) { + if (!hasDeclaredNonTrivialMember("toString", stringClass)) { generateDataClassToStringMethod(properties); } } - private void generateDataClassHashCodeIfNeeded(List properties) { + private void generateDataClassHashCodeIfNeeded(@NotNull List properties) { ClassDescriptor intClass = KotlinBuiltIns.getInstance().getInt(); - if (getDeclaredFunctionByRawSignature(descriptor, Name.identifier("hashCode"), intClass) == null) { + if (!hasDeclaredNonTrivialMember("hashCode", intClass)) { generateDataClassHashCodeMethod(properties); } } - private void generateDataClassEqualsIfNeeded(List properties) { + private void generateDataClassEqualsIfNeeded(@NotNull List 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 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 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 properties) { + private void generateDataClassHashCodeMethod(@NotNull List 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 properties) { + private void generateDataClassToStringMethod(@NotNull List properties) { MethodVisitor mv = v.getVisitor().visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null); InstructionAdapter iv = new InstructionAdapter(mv); diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/JavaToKotlinMethodMapGenerated.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/JavaToKotlinMethodMapGenerated.java index 9216273515f..de9d98188b4 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/JavaToKotlinMethodMapGenerated.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/kotlinSignature/JavaToKotlinMethodMapGenerated.java @@ -28,9 +28,15 @@ class JavaToKotlinMethodMapGenerated { JavaToKotlinMethodMapGenerated() { ImmutableMultimap.Builder 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>"), + 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"), 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>"), + 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"), pair("put(K, V)", "fun put(key: K, value: V): V?"), diff --git a/compiler/testData/builtin-classes.txt b/compiler/testData/builtin-classes.txt index 567d1ab1ebf..2d2394f9132 100644 --- a/compiler/testData/builtin-classes.txt +++ b/compiler/testData/builtin-classes.txt @@ -181,7 +181,7 @@ public final class ByteRange : jet.Range, jet.Progression { } } -public final class Char : jet.Hashable, jet.Comparable { +public final class Char : jet.Comparable { /*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 : jet.Iterable, jet.Hashable { +public trait Collection : jet.Iterable { public abstract fun contains(/*0*/ o: jet.Any?): jet.Boolean public abstract fun containsAll(/*0*/ c: jet.Collection): jet.Boolean public abstract fun isEmpty(): jet.Boolean @@ -756,9 +756,6 @@ public trait Function9 { /*primary*/ private constructor InlineStrategy() public final override /*1*/ /*fake_override*/ fun name(): jet.String @@ -1383,7 +1380,7 @@ public trait Map { public abstract fun size(): jet.Int public abstract fun values(): jet.Collection - public trait Entry : jet.Hashable { + public trait Entry { public abstract fun getKey(): K public abstract fun getValue(): V } @@ -1463,7 +1460,7 @@ public trait MutableMap : jet.Map { public abstract override /*1*/ /*fake_override*/ fun size(): jet.Int public abstract override /*1*/ fun values(): jet.MutableCollection - public trait MutableEntry : jet.Map.Entry, jet.Hashable { + public trait MutableEntry : jet.Map.Entry { 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 diff --git a/compiler/testData/codegen/box/fieldRename/genericPropertyWithItself.kt b/compiler/testData/codegen/box/fieldRename/genericPropertyWithItself.kt index e9378c0210d..ea584c3a917 100644 --- a/compiler/testData/codegen/box/fieldRename/genericPropertyWithItself.kt +++ b/compiler/testData/codegen/box/fieldRename/genericPropertyWithItself.kt @@ -1,7 +1,7 @@ public class MPair ( public val first: A ) { - fun equals(o: Any?): Boolean { + override fun equals(o: Any?): Boolean { val t = o as MPair<*> return first == t.first } diff --git a/compiler/testData/codegen/box/functions/defaultargs2.kt b/compiler/testData/codegen/box/functions/defaultargs2.kt index cf02fc34f39..710cc126ad2 100644 --- a/compiler/testData/codegen/box/functions/defaultargs2.kt +++ b/compiler/testData/codegen/box/functions/defaultargs2.kt @@ -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 && diff --git a/compiler/testData/codegen/box/package/checkCast.kt b/compiler/testData/codegen/box/package/checkCast.kt index 5615533f317..ffdfa30042b 100644 --- a/compiler/testData/codegen/box/package/checkCast.kt +++ b/compiler/testData/codegen/box/package/checkCast.kt @@ -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 diff --git a/compiler/testData/codegen/box/typeMapping/hashable.kt b/compiler/testData/codegen/box/typeMapping/hashable.kt deleted file mode 100644 index dbd74a0d5e3..00000000000 --- a/compiler/testData/codegen/box/typeMapping/hashable.kt +++ /dev/null @@ -1,6 +0,0 @@ -fun foo(): Hashable = 1 - -fun box(): String { - if (foo() == 1) return "OK" - return "Fail" -} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclared.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclared.kt index 9f631add9aa..5aaf2403250 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclared.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclared.kt @@ -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 { diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclaredWrongSignature.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclaredWrongSignature.kt index a2562a546ec..23dfbcdf820 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclaredWrongSignature.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/alreadyDeclaredWrongSignature.kt @@ -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 { diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/instanceof.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/instanceof.kt index 30416c7497a..809f5a9ff15 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/instanceof.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/instanceof.kt @@ -1,5 +1,5 @@ class Dummy { - fun equals(other: Any?) = true + override fun equals(other: Any?) = true } open data class A(val v: Any) diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/nullother.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/nullother.kt index 900db2781f7..bb0f764e061 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/nullother.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/equals/nullother.kt @@ -1,5 +1,5 @@ class Dummy { - fun equals(other: Any?) = true + override fun equals(other: Any?) = true } data class A(val v: Any?) diff --git a/compiler/testData/codegen/boxWithStdlib/dataClasses/hashcode/alreadyDeclared.kt b/compiler/testData/codegen/boxWithStdlib/dataClasses/hashcode/alreadyDeclared.kt index 73586f7f6d5..ee7b621c974 100644 --- a/compiler/testData/codegen/boxWithStdlib/dataClasses/hashcode/alreadyDeclared.kt +++ b/compiler/testData/codegen/boxWithStdlib/dataClasses/hashcode/alreadyDeclared.kt @@ -1,5 +1,5 @@ data class A(val x: Int) { - fun hashCode(): Int = -3 + override fun hashCode(): Int = -3 } fun box(): String { diff --git a/compiler/testData/codegen/boxWithStdlib/regressions/implicitlyCastToHashable.kt b/compiler/testData/codegen/boxWithStdlib/regressions/implicitlyCastToHashable.kt deleted file mode 100644 index 4f46a05f730..00000000000 --- a/compiler/testData/codegen/boxWithStdlib/regressions/implicitlyCastToHashable.kt +++ /dev/null @@ -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" -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt index db72b5d2cfe..0dafd7cc23a 100644 --- a/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt +++ b/compiler/testData/diagnostics/tests/BinaryCallsOnNullableValues.kt @@ -1,13 +1,5 @@ class A() { - fun equals(a : Any?) : Boolean = false -} - -class B() { - fun equals(a : Any?) : Boolean? = false -} - -class C() { - fun equals(a : Any?) : Int = 0 + override fun equals(other : Any?) : Boolean = false } fun f(): Unit { @@ -22,8 +14,6 @@ fun f(): Unit { x != 1 A() == 1 - B() == 1 - C() == 1 x === "1" x !== "1" diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt index 47400289be2..29ac268ad0f 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOut.kt @@ -1 +1 @@ -fun f(a: MutableList) = a is MutableList +fun f(a: MutableList) = a is MutableList diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt index 51395925aad..f1ba3800c08 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedAllowFromOutAtClass.kt @@ -1 +1 @@ -fun f(a: List) = a is List +fun f(a: List) = a is List diff --git a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.kt b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.kt index f7399ac62e2..9c8ae7059dc 100644 --- a/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.kt +++ b/compiler/testData/diagnostics/tests/cast/IsErasedDisallowFromOutAtClass.kt @@ -1 +1 @@ -fun f(a: List) = a is List +fun f(a: List) = a is List diff --git a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.kt b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.kt index 2d86a647a05..458cec1a151 100644 --- a/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.kt +++ b/compiler/testData/diagnostics/tests/j+k/SupertypeArgumentsNullability-UserTypes.kt @@ -15,7 +15,7 @@ public class Y extends X { // FILE: test.kt fun main() { - Y().foo().hashCode() + Y().foo().wait() Y().bar(null) } diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt index 14e3285695c..14356527b2f 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/superInExtensionFunctionCall.kt @@ -1,6 +1,6 @@ // No supertype at all class A1 { fun test() { - super.equals(null) // Call to an extension function + super.identityEquals(null) // Call to an extension function } } \ No newline at end of file diff --git a/compiler/testData/recursiveProcessor/declarations.txt b/compiler/testData/recursiveProcessor/declarations.txt index a3cf8078243..fd7a197e007 100644 --- a/compiler/testData/recursiveProcessor/declarations.txt +++ b/compiler/testData/recursiveProcessor/declarations.txt @@ -50,13 +50,35 @@ Trait.traitFunc:SimpleFunctionDescriptor Trait.traitProp:PropertyDescriptor Trait:ClassDescriptorWithResolutionScopes a:ValueParameterDescriptor +fake .equals:SimpleFunctionDescriptor +fake .hashCode:SimpleFunctionDescriptor +fake .equals:SimpleFunctionDescriptor +fake .hashCode:SimpleFunctionDescriptor +fake .equals:SimpleFunctionDescriptor +fake .hashCode:SimpleFunctionDescriptor fake .nestedFunc:SimpleFunctionDescriptor fake .:PropertyGetterDescriptor +fake .equals:SimpleFunctionDescriptor +fake .hashCode:SimpleFunctionDescriptor fake .objFunc:SimpleFunctionDescriptor fake .objProp:PropertyDescriptor fake Class.: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.:PropertyGetterDescriptor innerTest.: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 \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java index a6c768997c9..6c067bfb5e0 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index 8e75815961e..841380e34b7 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -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"); diff --git a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java index e3cbe31f768..5899e002084 100644 --- a/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java +++ b/compiler/tests/org/jetbrains/jet/types/JetTypeCheckerTest.java @@ -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"); 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"); + assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> null} ", "Comparable?"); + assertType("when (1) { is 1 -> 2; is 1 -> '2'; else -> null} ", "Comparable?"); + assertType("when (1) { is 1 -> 2; is 1 -> '2'; is 1 -> when(2) {is 1 -> null}} ", "Comparable?"); } 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"); 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"); + assertType("try {1} catch (e : Exception) {'a'}", "Comparable"); + assertType("try {1} catch (e : Exception) {'a'} catch (e : Exception) {null}", "Comparable?"); 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", "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"); diff --git a/core/builtins/native/jet/Any.kt b/core/builtins/native/jet/Any.kt index 636c32f49c1..c824db5c3f4 100644 --- a/core/builtins/native/jet/Any.kt +++ b/core/builtins/native/jet/Any.kt @@ -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 +} diff --git a/core/builtins/native/jet/Char.kt b/core/builtins/native/jet/Char.kt index 03c8082e7b2..40fbaa50dbf 100644 --- a/core/builtins/native/jet/Char.kt +++ b/core/builtins/native/jet/Char.kt @@ -1,6 +1,6 @@ package jet -public class Char private () : Hashable, Comparable { +public class Char private () : Comparable { 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 { public fun toChar() : Char public fun toShort() : Short public fun toByte() : Byte - - public override fun hashCode() : Int - public override fun equals(other : Any?) : Boolean } diff --git a/core/builtins/native/jet/Collections.kt b/core/builtins/native/jet/Collections.kt index d8c85d578a8..c237c3f4a09 100644 --- a/core/builtins/native/jet/Collections.kt +++ b/core/builtins/native/jet/Collections.kt @@ -8,7 +8,7 @@ public trait MutableIterable : Iterable { override fun iterator() : MutableIterator } -public trait Collection : Iterable, Hashable { +public trait Collection : Iterable { // Query Operations public fun size() : Int public fun isEmpty() : Boolean @@ -123,7 +123,7 @@ public trait Map { public fun values() : Collection public fun entrySet() : Set> - public trait Entry : Hashable { + public trait Entry { public fun getKey() : K public fun getValue() : V } @@ -143,7 +143,7 @@ public trait MutableMap : Map { override fun values() : MutableCollection override fun entrySet() : MutableSet> - public trait MutableEntry : Map.Entry, Hashable { + public trait MutableEntry : Map.Entry { public fun setValue(value : V) : V } -} +} \ No newline at end of file diff --git a/core/builtins/native/jet/Library.kt b/core/builtins/native/jet/Library.kt index 57671f7a650..141b8b81de2 100644 --- a/core/builtins/native/jet/Library.kt +++ b/core/builtins/native/jet/Library.kt @@ -4,27 +4,21 @@ public trait Annotation public annotation class volatile -public fun synchronized(lock: Any, block : () -> R) : R +public fun 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 { public fun compareTo(other : T) : Int } -public trait Hashable { - public fun hashCode() : Int - public fun equals(other : Any?) : Boolean -} - public class Boolean private () : Comparable { public fun not() : Boolean @@ -35,8 +29,6 @@ public class Boolean private () : Comparable { 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, 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 diff --git a/core/builtins/native/jet/Numbers.kt b/core/builtins/native/jet/Numbers.kt index af76f4e95bf..222748953e9 100644 --- a/core/builtins/native/jet/Numbers.kt +++ b/core/builtins/native/jet/Numbers.kt @@ -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 { @@ -85,9 +78,6 @@ public class Double private () : Number, Comparable { 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 { @@ -159,9 +149,6 @@ public class Float private () : Number, Comparable { 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 { @@ -241,9 +228,6 @@ public class Long private () : Number, Comparable { 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 { @@ -323,9 +307,6 @@ public class Int private () : Number, Comparable { 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 { @@ -397,9 +378,6 @@ public class Short private () : Number, Comparable { 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 { @@ -471,7 +449,4 @@ public class Byte private () : Number, Comparable { 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 } diff --git a/core/builtins/src/jet/Progressions.kt b/core/builtins/src/jet/Progressions.kt index e8a5d79a4e2..507eb64195b 100644 --- a/core/builtins/src/jet/Progressions.kt +++ b/core/builtins/src/jet/Progressions.kt @@ -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) diff --git a/core/builtins/src/jet/Ranges.kt b/core/builtins/src/jet/Ranges.kt index dad0dd7d252..8ff050f8914 100644 --- a/core/builtins/src/jet/Ranges.kt +++ b/core/builtins/src/jet/Ranges.kt @@ -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) diff --git a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java index 50a4c549b5c..fffdfc45c4d 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java +++ b/core/descriptor.loader.java/src/org/jetbrains/jet/lang/resolve/java/mapping/JavaToKotlinClassMapBuilder.java @@ -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()); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java index 633fa122d74..e78311178f5 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java @@ -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 - trait Collection: Iterable, Hashable + trait Collection: Iterable trait MyFooCollection: Collection> - For MyFunCollection, the following multimap will be returned: + For MyFooCollection, the following multimap will be returned: T declared in Iterable -> Foo E declared in Collection -> Foo F declared in MyFooCollection -> out CharSequence diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index 90e38b69c2e..e4b23435a17 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -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(), diff --git a/generators/src/org/jetbrains/jet/generators/builtins/progressions.kt b/generators/src/org/jetbrains/jet/generators/builtins/progressions.kt index 0dc3c4c7bd8..02eba150666 100644 --- a/generators/src/org/jetbrains/jet/generators/builtins/progressions.kt +++ b/generators/src/org/jetbrains/jet/generators/builtins/progressions.kt @@ -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}\""} }""") diff --git a/generators/src/org/jetbrains/jet/generators/builtins/ranges.kt b/generators/src/org/jetbrains/jet/generators/builtins/ranges.kt index 4e62a72492f..6ed53a96fde 100644 --- a/generators/src/org/jetbrains/jet/generators/builtins/ranges.kt +++ b/generators/src/org/jetbrains/jet/generators/builtins/ranges.kt @@ -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) diff --git a/idea/testData/checker/BinaryCallsOnNullableValues.kt b/idea/testData/checker/BinaryCallsOnNullableValues.kt index 9cf12a60527..8afde70b013 100644 --- a/idea/testData/checker/BinaryCallsOnNullableValues.kt +++ b/idea/testData/checker/BinaryCallsOnNullableValues.kt @@ -1,13 +1,5 @@ class A() { - fun equals(a : Any?) : Boolean = false -} - -class B() { - fun equals(a : Any?) : Boolean? = false -} - -class C() { - fun equals(a : Any?) : Int = 0 + override fun equals(a : Any?) : Boolean = false } fun f(): Unit { @@ -22,8 +14,6 @@ fun f(): Unit { x != 1 A() == 1 - B() == 1 - C() == 1 x === "1" x !== "1" diff --git a/idea/testData/completion/basic/common/InExpressionNoPrefix.kt b/idea/testData/completion/basic/common/InExpressionNoPrefix.kt index 443aeedb5af..0f3a3aa9f10 100644 --- a/idea/testData/completion/basic/common/InExpressionNoPrefix.kt +++ b/idea/testData/completion/basic/common/InExpressionNoPrefix.kt @@ -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 \ No newline at end of file diff --git a/idea/testData/completion/basic/common/InExtendTypeAnnotation.kt b/idea/testData/completion/basic/common/InExtendTypeAnnotation.kt index 86fe19bf78e..b9cefef7fa8 100644 --- a/idea/testData/completion/basic/common/InExtendTypeAnnotation.kt +++ b/idea/testData/completion/basic/common/InExtendTypeAnnotation.kt @@ -3,6 +3,5 @@ class Test : { } } -// EXIST: Any, Nothing, Unit, Int, Number -// EXIST: Array, Hashable +// EXIST: Any, Nothing, Unit, Int, Number, Array // EXIST_JAVA_ONLY: Math, Thread \ No newline at end of file diff --git a/idea/testData/highlighter/deprecated/Operation.kt b/idea/testData/highlighter/deprecated/Operation.kt index 449667b6cc9..0cff421b0ca 100644 --- a/idea/testData/highlighter/deprecated/Operation.kt +++ b/idea/testData/highlighter/deprecated/Operation.kt @@ -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 += x2 - x1 == x2 - x1 != x2 - x1 > x2 + x1..x2 } // NO_CHECK_INFOS diff --git a/idea/testData/quickfix/changeSignature/beforeAddParameterNotAvailableForBuiltins.kt b/idea/testData/quickfix/changeSignature/beforeAddParameterNotAvailableForBuiltins.kt index 085d255e09f..ddacfcd5b2e 100644 --- a/idea/testData/quickfix/changeSignature/beforeAddParameterNotAvailableForBuiltins.kt +++ b/idea/testData/quickfix/changeSignature/beforeAddParameterNotAvailableForBuiltins.kt @@ -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", "b") diff --git a/idea/testData/resolve/builtins/equals.kt b/idea/testData/resolve/builtins/equals.kt index 917dfc89bad..8430d403f73 100644 --- a/idea/testData/resolve/builtins/equals.kt +++ b/idea/testData/resolve/builtins/equals.kt @@ -1,2 +1,2 @@ val x = 5.equals(5) -//jet/Numbers.kt:equals +//jet/Any.kt:equals diff --git a/js/js.translator/testFiles/defaultArguments/cases/constructorCallWithDefArg2.kt b/js/js.translator/testFiles/defaultArguments/cases/constructorCallWithDefArg2.kt index a6777543922..4976cc1bbe8 100644 --- a/js/js.translator/testFiles/defaultArguments/cases/constructorCallWithDefArg2.kt +++ b/js/js.translator/testFiles/defaultArguments/cases/constructorCallWithDefArg2.kt @@ -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 } } diff --git a/js/js.translator/testFiles/expression/equals/cases/customEqualsMethod.kt b/js/js.translator/testFiles/expression/equals/cases/customEqualsMethod.kt index 595520c16a9..25775b2e914 100644 --- a/js/js.translator/testFiles/expression/equals/cases/customEqualsMethod.kt +++ b/js/js.translator/testFiles/expression/equals/cases/customEqualsMethod.kt @@ -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 } } diff --git a/js/js.translator/testFiles/expression/equals/cases/customEqualsMethodOnAny.kt b/js/js.translator/testFiles/expression/equals/cases/customEqualsMethodOnAny.kt index 8146c2b3cdb..cc65ba30e98 100644 --- a/js/js.translator/testFiles/expression/equals/cases/customEqualsMethodOnAny.kt +++ b/js/js.translator/testFiles/expression/equals/cases/customEqualsMethodOnAny.kt @@ -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 } } diff --git a/js/js.translator/testFiles/expression/equals/cases/explicitEqualsMethod.kt b/js/js.translator/testFiles/expression/equals/cases/explicitEqualsMethod.kt index 7301668272a..90e660a9252 100644 --- a/js/js.translator/testFiles/expression/equals/cases/explicitEqualsMethod.kt +++ b/js/js.translator/testFiles/expression/equals/cases/explicitEqualsMethod.kt @@ -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 } } diff --git a/js/js.translator/testFiles/expression/function/cases/manglingAnyMethods.kt b/js/js.translator/testFiles/expression/function/cases/manglingAnyMethods.kt index 3aa322618c3..971ae2fdf98 100644 --- a/js/js.translator/testFiles/expression/function/cases/manglingAnyMethods.kt +++ b/js/js.translator/testFiles/expression/function/cases/manglingAnyMethods.kt @@ -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" }