From b5ec30666bbd60a4a48a821f6ff236af68a477db Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Fri, 23 Dec 2016 11:28:12 +0100 Subject: [PATCH] Fix for KT-15410: "Protected function call from public-API inline function" for protected constructor call #KT-15410 Fixed --- .../resolve/calls/checkers/InlineChecker.java | 3 ++- .../diagnostics/tests/inline/kt15410.kt | 9 +++++++++ .../diagnostics/tests/inline/kt15410.txt | 18 ++++++++++++++++++ .../checkers/DiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/inline/kt15410.kt create mode 100644 compiler/testData/diagnostics/tests/inline/kt15410.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java index 6cf13bcf0be..71924fe8d91 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/InlineChecker.java @@ -258,7 +258,8 @@ class InlineChecker implements CallChecker { checkPrivateClassMemberAccess(calledDescriptor, expression, context); } - if (isInlineFunPublicOrPublishedApi && + if (!(calledDescriptor instanceof ConstructorDescriptor) && + isInlineFunPublicOrPublishedApi && inlineFunEffectiveVisibility.toVisibility() != Visibilities.PROTECTED && calledFunEffectiveVisibility.toVisibility() == Visibilities.PROTECTED) { context.getTrace().report(Errors.PROTECTED_CALL_FROM_PUBLIC_INLINE.on(expression, calledDescriptor)); diff --git a/compiler/testData/diagnostics/tests/inline/kt15410.kt b/compiler/testData/diagnostics/tests/inline/kt15410.kt new file mode 100644 index 00000000000..82654d42606 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt15410.kt @@ -0,0 +1,9 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +open class Foo protected constructor() + +inline fun foo(f: () -> Unit) = object: Foo() {} + +class A : Foo() { + inline fun foo(f: () -> Unit) = Foo() +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/kt15410.txt b/compiler/testData/diagnostics/tests/inline/kt15410.txt new file mode 100644 index 00000000000..bce77643ebd --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/kt15410.txt @@ -0,0 +1,18 @@ +package + +public inline fun foo(/*0*/ f: () -> kotlin.Unit): Foo + +public final class A : Foo { + public constructor A() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + public final inline fun foo(/*0*/ f: () -> kotlin.Unit): Foo + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +public open class Foo { + protected constructor Foo() + 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/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 3ddefe7a1d9..2ad007daa81 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -10933,6 +10933,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("kt15410.kt") + public void testKt15410() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inline/kt15410.kt"); + doTest(fileName); + } + @TestMetadata("kt4869.kt") public void testKt4869() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inline/kt4869.kt");