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

This commit is contained in:
Alexey Andreev
2017-01-30 14:25:03 +03:00
parent d117b0210f
commit 06e8f7b328
4 changed files with 42 additions and 2 deletions
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEPRECATION
// !DIAGNOSTICS: -DEPRECATION, -DEPRECATION_ERROR
@native("B")
<!JS_NAME_PROHIBITED_FOR_NAMED_NATIVE!>@JsName("C")<!>
class A
@@ -6,6 +6,8 @@ class B : A() {
<!OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS!>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 <!OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS_WITH_FAKE!>Y<!> : X(), I
class <!OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS_WITH_FAKE!>YY<!> : A(), II
external class YE: XE, I
class Z : X(), J
@@ -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
@@ -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) }
}