From 116380a826c5bf93913c12b220098e038f24a697 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 23 Mar 2017 14:52:06 +0300 Subject: [PATCH] Allow impl declarations to have non-stable parameter names #KT-17027 Fixed --- .../checkers/HeaderImplDeclarationChecker.kt | 2 +- .../multiplatform/java/parameterNames.kt | 18 +++++++++++++++ .../multiplatform/java/parameterNames.txt | 23 +++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 15 ++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.kt create mode 100644 compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/HeaderImplDeclarationChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/HeaderImplDeclarationChecker.kt index 68b47f4e980..770895ee9e4 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/HeaderImplDeclarationChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/checkers/HeaderImplDeclarationChecker.kt @@ -270,7 +270,7 @@ class HeaderImplDeclarationChecker(val moduleToCheck: ModuleDescriptor? = null) aExtensionReceiver?.type?.let(substitutor) != bExtensionReceiver?.type) return Incompatible.ParameterTypes if (substitutor(a.returnType) != b.returnType) return Incompatible.ReturnType - if (!equalsBy(aParams, bParams, ValueParameterDescriptor::getName)) return Incompatible.ParameterNames + if (b.hasStableParameterNames() && !equalsBy(aParams, bParams, ValueParameterDescriptor::getName)) return Incompatible.ParameterNames if (!equalsBy(aTypeParams, bTypeParams, TypeParameterDescriptor::getName)) return Incompatible.TypeParameterNames if (a.modality != b.modality) return Incompatible.Modality diff --git a/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.kt b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.kt new file mode 100644 index 00000000000..4fb79603210 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.kt @@ -0,0 +1,18 @@ +// !LANGUAGE: +MultiPlatformProjects +// MODULE: m1-common +// FILE: common.kt + +header class Foo { + fun foo(i: Int, d: Double, f: Float): Unit +} + +// MODULE: m2-jvm(m1-common) +// FILE: FooImpl.java + +public class FooImpl { + public final void foo(int d, double i, float f) {} +} + +// FILE: jvm.kt + +impl typealias Foo = FooImpl diff --git a/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.txt b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.txt new file mode 100644 index 00000000000..b52e6de9b59 --- /dev/null +++ b/compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.txt @@ -0,0 +1,23 @@ +// -- Module: -- +package + +public final header class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final header fun foo(/*0*/ i: kotlin.Int, /*1*/ d: kotlin.Double, /*2*/ f: kotlin.Float): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + + +// -- Module: -- +package + +public open class FooImpl { + public constructor FooImpl() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final fun foo(/*0*/ d: kotlin.Int, /*1*/ i: kotlin.Double, /*2*/ f: kotlin.Float): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} +public typealias Foo = FooImpl diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 245ebac10f2..d4ef5e4c8fd 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -13237,6 +13237,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { } } + @TestMetadata("compiler/testData/diagnostics/tests/multiplatform/java") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Java extends AbstractDiagnosticsTest { + public void testAllFilesPresentInJava() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/multiplatform/java"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true); + } + + @TestMetadata("parameterNames.kt") + public void testParameterNames() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/multiplatform/java/parameterNames.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/tests/multiplatform/topLevelFun") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)