From 06e8f7b328f78349cb4406e172125d7e15017f03 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 30 Jan 2017 14:25:03 +0300 Subject: [PATCH] JS: don't report error when FAKE function overrides external function with optional parameters. Report only when it overrides at least two such functions. See KT-15961 --- .../name/jsNameAndNamedNative.kt | 2 +- .../native/overrideOptionalParam.kt | 10 +++++++ .../native/overrideOptionalParam.txt | 30 +++++++++++++++++++ .../diagnostics/JsInheritanceChecker.kt | 2 +- 4 files changed, 42 insertions(+), 2 deletions(-) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndNamedNative.kt b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndNamedNative.kt index 83c98e304a4..923a7333cc7 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndNamedNative.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/name/jsNameAndNamedNative.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -DEPRECATION +// !DIAGNOSTICS: -DEPRECATION, -DEPRECATION_ERROR @native("B") @JsName("C") class A diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt index 534a9066415..8e565d72dbb 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.kt @@ -6,6 +6,8 @@ class B : A() { override fun f(x: Int) {} } +class BB : A() + external class C : A { override fun f(x: Int) } @@ -19,6 +21,12 @@ interface J { fun f(x: Int = 23) } +interface II { + fun f(x: Int) +} + +interface IIJ : II, J + open external class D { open fun f(x: Int) } @@ -45,6 +53,8 @@ open external class XE { class Y : X(), I +class YY : A(), II + external class YE: XE, I class Z : X(), J \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.txt b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.txt index db3a7949d40..550cba0aa79 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.txt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/overrideOptionalParam.txt @@ -16,6 +16,14 @@ public final class B : A { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +public final class BB : A { + public constructor BB() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun f(/*0*/ x: kotlin.Int = ...): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + public external final class C : A { public constructor C() public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean @@ -63,6 +71,20 @@ public external interface I { public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +public interface II { + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract fun f(/*0*/ x: kotlin.Int): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public interface IIJ : II, J { + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public abstract override /*2*/ /*fake_override*/ fun f(/*0*/ x: kotlin.Int = ...): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + public interface J { public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean public abstract fun f(/*0*/ x: kotlin.Int = ...): kotlin.Unit @@ -102,6 +124,14 @@ public external final class YE : XE, I { public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String } +public final class YY : A, II { + public constructor YY() + public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*2*/ /*fake_override*/ fun f(/*0*/ x: kotlin.Int = ...): kotlin.Unit + public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String +} + public final class Z : X, J { public constructor Z() public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsInheritanceChecker.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsInheritanceChecker.kt index 7d0de83e4d9..31394ef8d5f 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsInheritanceChecker.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/diagnostics/JsInheritanceChecker.kt @@ -71,7 +71,7 @@ object JsInheritanceChecker : SimpleDeclarationChecker { private fun findFakeMethodOverridingExternalWithOptionalParams(cls: ClassDescriptor): FunctionDescriptor? { val members = cls.unsubstitutedMemberScope.getContributedDescriptors(DescriptorKindFilter.CALLABLES) .mapNotNull { it as? FunctionDescriptor } - .filter { it.containingDeclaration == cls && !it.kind.isReal } + .filter { it.containingDeclaration == cls && !it.kind.isReal && it.overriddenDescriptors.size > 1 } return members.firstOrNull { isOverridingExternalWithOptionalParams(it) } }