From fe5fe63f0a2ddf75e5b6d59c9e44f5bec79a1870 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 20 Jun 2016 20:02:10 +0300 Subject: [PATCH] Fix visibility check for dynamic members within protected method #KT-11857 Fixed --- .../testsWithJsStdLib/dynamicTypes/protected.dynamic.txt | 3 +++ .../testsWithJsStdLib/dynamicTypes/protected.kt | 5 +++++ .../testsWithJsStdLib/dynamicTypes/protected.txt | 9 +++++++++ .../checkers/DiagnosticsTestWithJsStdLibGenerated.java | 6 ++++++ .../org/jetbrains/kotlin/descriptors/Visibilities.java | 3 ++- 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.dynamic.txt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.txt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.dynamic.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.dynamic.txt new file mode 100644 index 00000000000..bb2567a4447 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.dynamic.txt @@ -0,0 +1,3 @@ +public final var something: dynamic + public final fun (): dynamic + public final fun (/*0*/ : dynamic): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt new file mode 100644 index 00000000000..2192edd2531 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt @@ -0,0 +1,5 @@ +open class Foo { + open protected fun bar(a: dynamic){ + a.something + } +} diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.txt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.txt new file mode 100644 index 00000000000..9b15334d7f0 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.txt @@ -0,0 +1,9 @@ +package + +public open class Foo { + public constructor Foo() + protected open fun bar(/*0*/ a: dynamic): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index ff98c9468e5..00921aef65d 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -199,6 +199,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } + @TestMetadata("protected.kt") + public void testProtected() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/protected.kt"); + doTest(fileName); + } + @TestMetadata("reified.kt") public void testReified() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/reified.kt"); diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java index a305a06b8ec..5424b00d6a8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/Visibilities.java @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils; import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.kotlin.resolve.scopes.receivers.SuperCallReceiverValue; import org.jetbrains.kotlin.resolve.scopes.receivers.ThisClassReceiver; +import org.jetbrains.kotlin.types.DynamicTypesKt; import org.jetbrains.kotlin.types.KotlinType; import org.jetbrains.kotlin.util.ModuleVisibilityHelper; import org.jetbrains.kotlin.utils.CollectionsKt; @@ -192,7 +193,7 @@ public class Visibilities { ? ((SuperCallReceiverValue) receiver).getThisType() : receiver.getType(); - return DescriptorUtils.isSubtypeOfClass(actualReceiverType, fromClass); + return DescriptorUtils.isSubtypeOfClass(actualReceiverType, fromClass) || DynamicTypesKt.isDynamic(actualReceiverType); } };