Introduce error for PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE
^KT-42972 Fixed
This commit is contained in:
+6
@@ -15795,6 +15795,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt21177Warning.kt")
|
||||
public void testKt21177Warning() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177Warning.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt4869.kt")
|
||||
public void testKt4869() throws Exception {
|
||||
|
||||
+6
@@ -15795,6 +15795,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt21177Warning.kt")
|
||||
public void testKt21177Warning() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177Warning.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt4869.kt")
|
||||
public void testKt4869() throws Exception {
|
||||
|
||||
@@ -1163,7 +1163,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtDeclaration> INLINE_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<KtAnnotationEntry> NON_INTERNAL_PUBLISHED_API = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactoryForDeprecation1<PsiElement, CallableDescriptor> PROTECTED_CALL_FROM_PUBLIC_INLINE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitProtectedCallFromInline);
|
||||
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactoryForDeprecation1<PsiElement, CallableDescriptor> PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitProtectedConstructorCallFromPublicInline);
|
||||
DiagnosticFactoryForDeprecation1<PsiElement, CallableDescriptor> SUPER_CALL_FROM_PUBLIC_INLINE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitSuperCallsFromPublicInline);
|
||||
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> NOT_SUPPORTED_INLINE_PARAMETER_IN_INLINE_PARAMETER_DEFAULT_VALUE = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
@@ -277,7 +277,9 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
||||
calledFunEffectiveVisibility.toVisibility() === Visibilities.Protected) {
|
||||
when {
|
||||
isConstructorCall -> {
|
||||
context.trace.report(PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE.on(expression, calledDescriptor))
|
||||
context.trace.report(
|
||||
PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE.on(context.languageVersionSettings, expression, calledDescriptor)
|
||||
)
|
||||
}
|
||||
else -> {
|
||||
context.trace.report(
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ open class Foo protected constructor()
|
||||
inline fun foo(f: () -> Unit) = object: Foo() {}
|
||||
|
||||
class A : Foo() {
|
||||
inline fun foo(f: () -> Unit) = <!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE, PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>Foo<!>()
|
||||
inline fun foo(f: () -> Unit) = <!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE_ERROR, PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>Foo<!>()
|
||||
}
|
||||
|
||||
+2
-2
@@ -6,13 +6,13 @@ class SomeContainer {
|
||||
protected fun makeLimit(): Limit = TODO()
|
||||
|
||||
public inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE!>Limit<!>()
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE_ERROR!>Limit<!>()
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>makeLimit<!>()
|
||||
}
|
||||
}
|
||||
|
||||
open class A protected constructor() {
|
||||
inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE!>A<!>()
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE_ERROR!>A<!>()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: -ProhibitProtectedConstructorCallFromPublicInline
|
||||
|
||||
class SomeContainer {
|
||||
protected class Limit
|
||||
|
||||
protected fun makeLimit(): Limit = TODO()
|
||||
|
||||
public inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE!>Limit<!>()
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>makeLimit<!>()
|
||||
}
|
||||
}
|
||||
|
||||
open class A protected constructor() {
|
||||
inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE!>A<!>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
// !LANGUAGE: -ProhibitProtectedConstructorCallFromPublicInline
|
||||
|
||||
class SomeContainer {
|
||||
protected class Limit
|
||||
|
||||
protected fun makeLimit(): Limit = TODO()
|
||||
|
||||
public inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE_WARNING!>Limit<!>()
|
||||
<!PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR!>makeLimit<!>()
|
||||
}
|
||||
}
|
||||
|
||||
open class A protected constructor() {
|
||||
inline fun foo(f: () -> Unit) {
|
||||
<!PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE_WARNING!>A<!>()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public open class A {
|
||||
protected 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): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class SomeContainer {
|
||||
public constructor SomeContainer()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final inline fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
protected final fun makeLimit(): SomeContainer.Limit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
protected final class Limit {
|
||||
public constructor Limit()
|
||||
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
|
||||
}
|
||||
}
|
||||
Generated
+6
@@ -15801,6 +15801,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt21177Warning.kt")
|
||||
public void testKt21177Warning() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/inline/kt21177Warning.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt4869.kt")
|
||||
public void testKt4869() throws Exception {
|
||||
|
||||
@@ -215,6 +215,7 @@ enum class LanguageFeature(
|
||||
UseBuilderInferenceOnlyIfNeeded(KOTLIN_1_6),
|
||||
SuspendConversion(KOTLIN_1_6),
|
||||
ProhibitSuperCallsFromPublicInline(KOTLIN_1_6),
|
||||
ProhibitProtectedConstructorCallFromPublicInline(KOTLIN_1_6),
|
||||
|
||||
// 1.7
|
||||
|
||||
|
||||
Reference in New Issue
Block a user