From 8311c1f0e203b899bd119afce0d648dac1594f58 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Thu, 2 Jul 2020 15:35:14 +0300 Subject: [PATCH] [FIR] Fix projection of Comparable supertype for ILT #KT-39048 Fixed --- .../inference/integerLiteralAsComparable.kt | 14 ++++++++++++++ .../inference/integerLiteralAsComparable.txt | 11 +++++++++++ .../kotlin/fir/FirDiagnosticsTestGenerated.java | 5 +++++ .../FirDiagnosticsWithLightTreeTestGenerated.java | 5 +++++ .../kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt | 2 +- .../kt26103_contravariantUnderlyingType.kt | 1 - .../codegen/box/primitiveTypes/unboxComparable.kt | 1 - .../box/ranges/contains/inComparableRange.kt | 1 - 8 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.txt diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt b/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt new file mode 100644 index 00000000000..59cef711f34 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt @@ -0,0 +1,14 @@ +// ISSUE: KT-39048 + +// FILE: JavaClass.java +public class JavaClass> { + public JavaClass(T from) {} +} + +// FILE: main.kt + +class K>(t: T) +fun main() { + K(0) + JavaClass(0) +} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.txt b/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.txt new file mode 100644 index 00000000000..a8fe3f11fc7 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.txt @@ -0,0 +1,11 @@ +FILE: main.kt + public final class K|> : R|kotlin/Any| { + public constructor|>(t: R|T|): R|K| { + super() + } + + } + public final fun main(): R|kotlin/Unit| { + R|/K.K|(Int(0)) + R|/JavaClass.JavaClass|!|>(Int(0)) + } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 399b7db3ffd..ea5bd65c7b8 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1479,6 +1479,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/inference/extensionCallableReferences.kt"); } + @TestMetadata("integerLiteralAsComparable.kt") + public void testIntegerLiteralAsComparable() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt"); + } + @TestMetadata("intersectionTypesInConstraints.kt") public void testIntersectionTypesInConstraints() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/intersectionTypesInConstraints.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index 33a1422d506..fe92557fc21 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1479,6 +1479,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/inference/extensionCallableReferences.kt"); } + @TestMetadata("integerLiteralAsComparable.kt") + public void testIntegerLiteralAsComparable() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/inference/integerLiteralAsComparable.kt"); + } + @TestMetadata("intersectionTypesInConstraints.kt") public void testIntersectionTypesInConstraints() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/inference/intersectionTypesInConstraints.kt"); diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt index 41c854c2e7b..9def441fddf 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/types/ConeIntegerLiteralTypeImpl.kt @@ -59,7 +59,7 @@ class ConeIntegerLiteralTypeImpl : ConeIntegerLiteralType { override val supertypes: List by lazy { listOf( NUMBER_TYPE, - ConeClassLikeTypeImpl(COMPARABLE_TAG, arrayOf(ConeKotlinTypeProjectionOut(this)), false) + ConeClassLikeTypeImpl(COMPARABLE_TAG, arrayOf(ConeKotlinTypeProjectionIn(this)), false) ) } diff --git a/compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt b/compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt index 0a28754295e..11ddde91254 100644 --- a/compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt +++ b/compiler/testData/codegen/box/inlineClasses/kt26103_contravariantUnderlyingType.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +InlineClasses -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME inline class GCmp(val xc: Comparable) diff --git a/compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt b/compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt index a14f2452688..870989087fd 100644 --- a/compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt +++ b/compiler/testData/codegen/box/primitiveTypes/unboxComparable.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun foo(x: Int) = x fun bar(x: Comparable) = if (x is Int) foo(x) else 0 diff --git a/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt b/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt index b975a935449..8e4fdb3c09a 100644 --- a/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt +++ b/compiler/testData/codegen/box/ranges/contains/inComparableRange.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not