From f3ca46564784aeb9483cf58f7f81eeeff217e204 Mon Sep 17 00:00:00 2001 From: Nikolay Lunyak Date: Mon, 24 Apr 2023 15:14:51 +0300 Subject: [PATCH] [FIR] Freeze the current behavior of `ImplicitIntegerCoercion`+overloads Adding the tests "just in case", ensuring the K2 behaves similar to K1. --- ...CompilerTestFE10TestdataTestGenerated.java | 6 +++++ ...sticCompilerFE10TestDataTestGenerated.java | 6 +++++ ...eeOldFrontendDiagnosticsTestGenerated.java | 6 +++++ ...siOldFrontendDiagnosticsTestGenerated.java | 6 +++++ .../implicitIntegerCoercionOverloading.fir.kt | 25 +++++++++++++++++++ .../implicitIntegerCoercionOverloading.kt | 25 +++++++++++++++++++ .../test/runners/DiagnosticTestGenerated.java | 6 +++++ 7 files changed, 80 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.fir.kt create mode 100644 compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java index 7545913d5f7..ead1ba62346 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/DiagnosticCompilerTestFE10TestdataTestGenerated.java @@ -33997,6 +33997,12 @@ public class DiagnosticCompilerTestFE10TestdataTestGenerated extends AbstractDia runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloading.kt") + public void testImplicitIntegerCoercionOverloading() throws Exception { + runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt"); + } + @Test @TestMetadata("inferenceForSignedAndUnsignedTypes.kt") public void testInferenceForSignedAndUnsignedTypes() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java index 0ada1034efc..540812b3150 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated.java @@ -33997,6 +33997,12 @@ public class LLFirPreresolvedReversedDiagnosticCompilerFE10TestDataTestGenerated runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloading.kt") + public void testImplicitIntegerCoercionOverloading() throws Exception { + runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt"); + } + @Test @TestMetadata("inferenceForSignedAndUnsignedTypes.kt") public void testInferenceForSignedAndUnsignedTypes() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java index 35ca60db672..9a589beb746 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirLightTreeOldFrontendDiagnosticsTestGenerated.java @@ -33997,6 +33997,12 @@ public class FirLightTreeOldFrontendDiagnosticsTestGenerated extends AbstractFir runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloading.kt") + public void testImplicitIntegerCoercionOverloading() throws Exception { + runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt"); + } + @Test @TestMetadata("inferenceForSignedAndUnsignedTypes.kt") public void testInferenceForSignedAndUnsignedTypes() throws Exception { diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java index 0fbf7828ec5..03ff0bdedcd 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirPsiOldFrontendDiagnosticsTestGenerated.java @@ -34093,6 +34093,12 @@ public class FirPsiOldFrontendDiagnosticsTestGenerated extends AbstractFirPsiDia runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloading.kt") + public void testImplicitIntegerCoercionOverloading() throws Exception { + runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt"); + } + @Test @TestMetadata("inferenceForSignedAndUnsignedTypes.kt") public void testInferenceForSignedAndUnsignedTypes() throws Exception { diff --git a/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.fir.kt b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.fir.kt new file mode 100644 index 00000000000..061d2442296 --- /dev/null +++ b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.fir.kt @@ -0,0 +1,25 @@ +// ISSUE: KT-57655 +// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion +// ALLOW_KOTLIN_PACKAGE + +// FILE: annotation.kt + +package kotlin.internal + +annotation class ImplicitIntegerCoercion + +// FILE: test.kt + +import kotlin.internal.ImplicitIntegerCoercion + +fun test(@ImplicitIntegerCoercion x: UInt) = x +fun test(@ImplicitIntegerCoercion x: ULong) = x +fun testLong(@ImplicitIntegerCoercion x: ULong) = x + +fun box(): String = when { + test(5) != 5.toUInt() -> "Fail: test(5)" + test(5L) != 5L.toULong() -> "Fail: test(5L)" + testLong(5) != 5L.toULong() -> "Fail: test(5L)" + testLong(5L) != 5L.toULong() -> "Fail: test(5L)" + else -> "OK" +} diff --git a/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt new file mode 100644 index 00000000000..772e59920ae --- /dev/null +++ b/compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt @@ -0,0 +1,25 @@ +// ISSUE: KT-57655 +// !LANGUAGE: +ImplicitSignedToUnsignedIntegerConversion +// ALLOW_KOTLIN_PACKAGE + +// FILE: annotation.kt + +package kotlin.internal + +annotation class ImplicitIntegerCoercion + +// FILE: test.kt + +import kotlin.internal.ImplicitIntegerCoercion + +fun test(@ImplicitIntegerCoercion x: UInt) = x +fun test(@ImplicitIntegerCoercion x: ULong) = x +fun testLong(@ImplicitIntegerCoercion x: ULong) = x + +fun box(): String = when { + test(5) != 5.toUInt() -> "Fail: test(5)" + test(5L) != 5L.toULong() -> "Fail: test(5L)" + testLong(5) != 5L.toULong() -> "Fail: test(5L)" + testLong(5L) != 5L.toULong() -> "Fail: test(5L)" + else -> "OK" +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 26e357c44ea..8d1b6ab58ee 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -34865,6 +34865,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionNamedArg.kt"); } + @Test + @TestMetadata("implicitIntegerCoercionOverloading.kt") + public void testImplicitIntegerCoercionOverloading() throws Exception { + runTest("compiler/testData/diagnostics/tests/unsignedTypes/conversions/implicitIntegerCoercionOverloading.kt"); + } + @Test @TestMetadata("inferenceForSignedAndUnsignedTypes.kt") public void testInferenceForSignedAndUnsignedTypes() throws Exception {