Deprecate protected constructors call from public inline function
#KT-21177
This commit is contained in:
+5
@@ -12386,6 +12386,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt21177.kt")
|
||||||
|
public void testKt21177() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4869.kt")
|
@TestMetadata("kt4869.kt")
|
||||||
public void testKt4869() throws Exception {
|
public void testKt4869() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
||||||
|
|||||||
@@ -1130,6 +1130,7 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<KtDeclaration> INLINE_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
DiagnosticFactory0<KtDeclaration> INLINE_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> NON_INTERNAL_PUBLISHED_API = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> NON_INTERNAL_PUBLISHED_API = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING);
|
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING);
|
||||||
|
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory1.create(WARNING);
|
||||||
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<PsiElement, CallableDescriptor> PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE = DiagnosticFactory2.create(ERROR);
|
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);
|
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> NOT_SUPPORTED_INLINE_PARAMETER_IN_INLINE_PARAMETER_DEFAULT_VALUE = DiagnosticFactory2.create(ERROR);
|
||||||
|
|||||||
+1
@@ -1018,6 +1018,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(INLINE_PROPERTY_WITH_BACKING_FIELD, "Inline property cannot have backing field");
|
MAP.put(INLINE_PROPERTY_WITH_BACKING_FIELD, "Inline property cannot have backing field");
|
||||||
MAP.put(NON_INTERNAL_PUBLISHED_API, "@PublishedApi annotation is only applicable for internal declaration");
|
MAP.put(NON_INTERNAL_PUBLISHED_API, "@PublishedApi annotation is only applicable for internal declaration");
|
||||||
MAP.put(PROTECTED_CALL_FROM_PUBLIC_INLINE, "Protected function call from public-API inline function is deprecated", NAME);
|
MAP.put(PROTECTED_CALL_FROM_PUBLIC_INLINE, "Protected function call from public-API inline function is deprecated", NAME);
|
||||||
|
MAP.put(PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE, "Protected constructor call from public-API inline function is deprecated", NAME);
|
||||||
MAP.put(PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR, "Protected function call from public-API inline function is prohibited", NAME);
|
MAP.put(PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR, "Protected function call from public-API inline function is prohibited", NAME);
|
||||||
MAP.put(INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE, "Invalid default value for inline parameter: ''{0}''. Only lambdas, anonymous functions, and callable references are supported", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
|
MAP.put(INVALID_DEFAULT_FUNCTIONAL_PARAMETER_FOR_INLINE, "Invalid default value for inline parameter: ''{0}''. Only lambdas, anonymous functions, and callable references are supported", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
|
||||||
MAP.put(NOT_SUPPORTED_INLINE_PARAMETER_IN_INLINE_PARAMETER_DEFAULT_VALUE, "Usage of inline parameter ''{0}'' in default value for another inline parameter is not supported", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
|
MAP.put(NOT_SUPPORTED_INLINE_PARAMETER_IN_INLINE_PARAMETER_DEFAULT_VALUE, "Usage of inline parameter ''{0}'' in default value for another inline parameter is not supported", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
|
||||||
|
|||||||
@@ -265,14 +265,21 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
|||||||
checkPrivateClassMemberAccess(calledDescriptor, expression, context)
|
checkPrivateClassMemberAccess(calledDescriptor, expression, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calledDescriptor !is ConstructorDescriptor &&
|
val isConstructorCall = calledDescriptor is ConstructorDescriptor
|
||||||
|
if ((!isConstructorCall || expression !is KtConstructorCalleeExpression) &&
|
||||||
isInlineFunPublicOrPublishedApi &&
|
isInlineFunPublicOrPublishedApi &&
|
||||||
inlineFunEffectiveVisibility.toVisibility() !== Visibilities.Protected &&
|
inlineFunEffectiveVisibility.toVisibility() !== Visibilities.Protected &&
|
||||||
calledFunEffectiveVisibility.toVisibility() === Visibilities.Protected) {
|
calledFunEffectiveVisibility.toVisibility() === Visibilities.Protected) {
|
||||||
if (prohibitProtectedCallFromInline) {
|
when {
|
||||||
context.trace.report(PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR.on(expression, calledDescriptor))
|
isConstructorCall -> {
|
||||||
} else {
|
context.trace.report(PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE.on(expression, calledDescriptor))
|
||||||
context.trace.report(PROTECTED_CALL_FROM_PUBLIC_INLINE.on(expression, calledDescriptor))
|
}
|
||||||
|
prohibitProtectedCallFromInline -> {
|
||||||
|
context.trace.report(PROTECTED_CALL_FROM_PUBLIC_INLINE_ERROR.on(expression, calledDescriptor))
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
context.trace.report(PROTECTED_CALL_FROM_PUBLIC_INLINE.on(expression, calledDescriptor))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -6,5 +6,5 @@ open class Foo protected constructor()
|
|||||||
inline fun foo(f: () -> Unit) = object: Foo() {}
|
inline fun foo(f: () -> Unit) = object: Foo() {}
|
||||||
|
|
||||||
class A : Foo() {
|
class A : Foo() {
|
||||||
inline fun foo(f: () -> Unit) = <!PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>Foo<!>()
|
inline fun foo(f: () -> Unit) = <!NI;PROTECTED_CONSTRUCTOR_CALL_FROM_PUBLIC_INLINE, PROTECTED_CONSTRUCTOR_NOT_IN_SUPER_CALL!>Foo<!>()
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
class SomeContainer {
|
||||||
|
protected class Limit
|
||||||
|
|
||||||
|
protected fun makeLimit(): Limit = TODO()
|
||||||
|
|
||||||
|
public inline fun foo(f: () -> Unit) {
|
||||||
|
Limit()
|
||||||
|
makeLimit()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
open class A protected constructor() {
|
||||||
|
inline fun foo(f: () -> Unit) {
|
||||||
|
A()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
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,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
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12393,6 +12393,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
|||||||
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt21177.kt")
|
||||||
|
public void testKt21177() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4869.kt")
|
@TestMetadata("kt4869.kt")
|
||||||
public void testKt4869() throws Exception {
|
public void testKt4869() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
||||||
|
|||||||
Generated
+5
@@ -12388,6 +12388,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt19679.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt21177.kt")
|
||||||
|
public void testKt21177() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/inline/kt21177.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt4869.kt")
|
@TestMetadata("kt4869.kt")
|
||||||
public void testKt4869() throws Exception {
|
public void testKt4869() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
runTest("compiler/testData/diagnostics/tests/inline/kt4869.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user