diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index f7d758f8362..11e74e1423b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -2390,6 +2390,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt"); } + @Test + @TestMetadata("int2IntMap.kt") + public void testInt2IntMap() throws Exception { + runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt"); + } + @Test @TestMetadata("Iterator.kt") public void testIterator() throws Exception { diff --git a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaOverrideChecker.kt b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaOverrideChecker.kt index ef6cda97df8..a2480e1029d 100644 --- a/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaOverrideChecker.kt +++ b/compiler/fir/java/src/org/jetbrains/kotlin/fir/java/scopes/JavaOverrideChecker.kt @@ -66,11 +66,23 @@ class JavaOverrideChecker internal constructor( candidateTypeRef: FirTypeRef, baseTypeRef: FirTypeRef, substitutor: ConeSubstitutor - ) = isEqualTypes( - candidateTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack), - baseTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack), - substitutor - ) + ): Boolean { + val candidateType = candidateTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack) + val baseType = baseTypeRef.toConeKotlinTypeProbablyFlexible(session, javaTypeParameterStack) + + if (candidateType.isPrimitiveInJava() != baseType.isPrimitiveInJava()) return false + + return isEqualTypes( + candidateType, + baseType, + substitutor + ) + } + + private fun ConeKotlinType.isPrimitiveInJava(): Boolean = with(context) { + // TODO: Support enhanced type like `@NotNull Integer` that are not nullable, but still aren't primitive + !isNullableType() && isPrimitiveOrNullablePrimitive + } private fun isEqualArrayElementTypeProjections( candidateTypeProjection: ConeTypeProjection, diff --git a/compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt b/compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt new file mode 100644 index 00000000000..0293fb86084 --- /dev/null +++ b/compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt @@ -0,0 +1,100 @@ +// TARGET_BACKEND: JVM +// JVM_TARGET: 1.8 + +// FILE: Int2IntFunction.java +public interface Int2IntFunction { + boolean containsKey(int key); + + @Deprecated + default boolean containsKey(Object key) { + return false; + } +} +// FILE: Int2IntMap.java +public interface Int2IntMap extends Int2IntFunction, java.util.Map { + boolean containsKey(int var1); + + @Deprecated + default boolean containsKey(Object key) { + return Int2IntFunction.super.containsKey(key); + } +} + +// FILE: Int2IntMapImpl.java +import java.util.Collection; +import java.util.Map; +import java.util.Set; + +public class Int2IntMapImpl implements Int2IntMap { + @Override + public boolean containsKey(int var1) { + return var1 == 56; + } + + @Override + public int size() { + return 0; + } + + @Override + public boolean isEmpty() { + return false; + } + + @Override + public boolean containsValue(Object value) { + return false; + } + + @Override + public Integer get(Object key) { + return null; + } + + @Override + public Integer put(Integer key, Integer value) { + return null; + } + + @Override + public Integer remove(Object key) { + return null; + } + + @Override + public void putAll(Map m) { + + } + + @Override + public void clear() { + + } + + @Override + public Set keySet() { + return null; + } + + @Override + public Collection values() { + return null; + } + + @Override + public Set> entrySet() { + return null; + } +} + + +// FILE: m.kt +fun foo(x: Int2IntMap): String { + if (!x.containsKey(56)) return "fail 1" + if (x.containsKey(239)) return "fail 1" + return "OK" +} + +fun box(): String { + return foo(Int2IntMapImpl()) +} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt index 1a501bd20ef..d309f556472 100644 --- a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/notNullAnnotated.fir.kt @@ -17,6 +17,6 @@ public class B extends A { fun foo(b: B) { // See KT-9182 - b.foo(1) + b.foo(1) b.bar(2.0) } diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt deleted file mode 100644 index 2600623f44e..00000000000 --- a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.fir.kt +++ /dev/null @@ -1,113 +0,0 @@ -// FILE: AbstractSpecializedMap.java -public abstract class AbstractSpecializedMap implements java.util.Map { - public abstract double put(int x, double y); - public abstract double remove(int k); - public abstract double get(int k); - - public abstract boolean containsKey(int k); - public boolean containsKey(Object x) { - return false; - } - - public abstract boolean containsValue(double v); - public boolean containsValue(Object x) { - return false; - } -} - -// FILE: SpecializedMap.java -import org.jetbrains.annotations.NotNull; - -import java.util.Collection; -import java.util.Map; -import java.util.Set; - -public class SpecializedMap extends AbstractSpecializedMap { - public double put(int x, double y) { - return 123.0; - } - - @Override - public Double get(Object key) { - return null; - } - - @Override - public Double put(Integer key, Double value) { - return null; - } - - public double remove(int k) { - return 456.0; - } - - - public Double remove(Object ok) { - return null; - } - - - public double get(int k) { - return 789.0; - } - - public boolean containsKey(int k) { - return true; - } - - public boolean containsValue(double v) { - return true; - } - - @Override - public void putAll(Map m) { - } - - @Override - public void clear() { - - } - - @NotNull - @Override - public Set keySet() { - return null; - } - - @NotNull - @Override - public Collection values() { - return null; - } - - @NotNull - @Override - public Set> entrySet() { - return null; - } - - @Override - public int size() { - return 0; - } - - @Override - public boolean isEmpty() { - return false; - } -} - -// FILE: main.kt -fun foo(x: SpecializedMap) { - x.containsKey(1) - x.containsKey(null) - - x.get(2) - x.get(null) - - x.remove(3) - x.remove(null) - - x.put(4, 5.0) - x.put(4, null) -} diff --git a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.kt b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.kt index 1aaaa82660d..f26f5d83449 100644 --- a/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.kt +++ b/compiler/testData/diagnostics/tests/j+k/primitiveOverrides/specializedMap.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: AbstractSpecializedMap.java public abstract class AbstractSpecializedMap implements java.util.Map { public abstract double put(int x, double y); diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index be4657a913a..573ccc8a24c 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -2294,6 +2294,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt"); } + @Test + @TestMetadata("int2IntMap.kt") + public void testInt2IntMap() throws Exception { + runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt"); + } + @Test @TestMetadata("Iterator.kt") public void testIterator() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index 5bca20e7d0e..c292033aa55 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -2390,6 +2390,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt"); } + @Test + @TestMetadata("int2IntMap.kt") + public void testInt2IntMap() throws Exception { + runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt"); + } + @Test @TestMetadata("Iterator.kt") public void testIterator() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index acce3a43524..5e7398cd509 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -2014,6 +2014,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/builtinStubMethods/inheritedImplementations.kt"); } + @TestMetadata("int2IntMap.kt") + public void testInt2IntMap() throws Exception { + runTest("compiler/testData/codegen/box/builtinStubMethods/int2IntMap.kt"); + } + @TestMetadata("Iterator.kt") public void testIterator() throws Exception { runTest("compiler/testData/codegen/box/builtinStubMethods/Iterator.kt");