FE 10: wrap ext. receiver inlining prohibition in the language feature

See KT-52502
This commit is contained in:
Mikhail Glukhikh
2022-05-24 15:45:09 +02:00
committed by Space
parent fad35b95d4
commit d7ca7e17c9
37 changed files with 126 additions and 1 deletions
@@ -16926,6 +16926,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/inline/extensionOnFunction.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_after.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_after() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_after.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_before.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_before() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_before.kt");
}
@Test
@TestMetadata("fromInlineToNoInline.kt")
public void testFromInlineToNoInline() throws Exception {
@@ -16926,6 +16926,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/inline/extensionOnFunction.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_after.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_after() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_after.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_before.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_before() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_before.kt");
}
@Test
@TestMetadata("fromInlineToNoInline.kt")
public void testFromInlineToNoInline() throws Exception {
@@ -16926,6 +16926,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/inline/extensionOnFunction.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_after.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_after() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_after.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_before.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_before() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_before.kt");
}
@Test
@TestMetadata("fromInlineToNoInline.kt")
public void testFromInlineToNoInline() throws Exception {
@@ -1266,6 +1266,7 @@ public interface Errors {
DiagnosticFactory1.create(ERROR, NOT_SUPPORTED_IN_INLINE_MOST_RELEVANT);
DiagnosticFactory0<PsiElement> NOTHING_TO_INLINE = DiagnosticFactory0.create(WARNING);
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> USAGE_IS_NOT_INLINABLE_WARNING = DiagnosticFactory2.create(WARNING);
DiagnosticFactory2<KtElement, KtElement, DeclarationDescriptor> NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR);
DiagnosticFactory2<KtElement, KtElement, DeclarationDescriptor> RECURSION_IN_INLINE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<KtDeclaration> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR, INLINE_FUN_MODIFIER);
@@ -1085,6 +1085,7 @@ public class DefaultErrorMessages {
MAP.put(REIFIED_TYPE_PARAMETER_IN_OVERRIDE, "Override by a function with reified type parameter");
MAP.put(NOTHING_TO_INLINE, "Expected performance impact from inlining is insignificant. Inlining works best for functions with parameters of functional types");
MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Add ''noinline'' modifier to the parameter declaration", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
MAP.put(USAGE_IS_NOT_INLINABLE_WARNING, "Deprecated usage of inline-parameter ''{0}'' in ''{1}''. Add ''noinline'' modifier to the parameter declaration. See https://youtrack.jetbrains.com/issue/KT-52502", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Add ''noinline'' modifier to the parameter declaration or make its type not nullable", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
MAP.put(RECURSION_IN_INLINE, "Inline function ''{1}'' cannot be recursive", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
MAP.put(INLINE_PROPERTY_WITH_BACKING_FIELD, "Inline property cannot have backing field");
@@ -218,7 +218,13 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
) {
val inlinableCall = isInvokeOrInlineExtension(callDescriptor)
if (!inlinableCall) {
context.trace.report(USAGE_IS_NOT_INLINABLE.on(receiverExpression, receiverExpression, descriptor))
if (InlineUtil.isInline(callDescriptor) &&
!context.languageVersionSettings.supportsFeature(LanguageFeature.ForbidExtensionCallsOnInlineFunctionalParameters)
) {
context.trace.report(USAGE_IS_NOT_INLINABLE_WARNING.on(receiverExpression, receiverExpression, descriptor))
} else {
context.trace.report(USAGE_IS_NOT_INLINABLE.on(receiverExpression, receiverExpression, descriptor))
}
} else {
checkNonLocalReturn(context, lambdaDescriptor, receiverExpression)
}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
operator inline fun <T, U> Function1<T, U>.get(index : Int) {
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -NON_LOCAL_RETURN_NOT_ALLOWED
operator fun <T, U> Function1<T, U>.minusAssign(p: Function1<T, U>) {}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline operator fun <T, U> Function1<T, U>.compareTo(p: Function1<T, U>) = 1
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline operator fun <T, U> Function1<T, U>.component1() = 1
inline operator fun <T, U> Function1<T, U>.component2() = 2
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
inline operator fun <T, U> Function1<T, U>.component1() = 1
inline operator fun <T, U> Function1<T, U>.component2() = 2
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
operator inline fun <T, U> Function1<T, U>.contains(p: Function1<T, U>): Boolean {
this in <!USAGE_IS_NOT_INLINABLE!>p<!>
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -CONFLICTING_JVM_DECLARATIONS -CONFLICTING_OVERLOADS
operator fun <T, U> Function1<T, U>.minus(p: Function1<T, U>) {
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
inline operator fun <T, U> Function1<T, U>.rangeTo(p: Function1<T, U>): ClosedRange<Int> {
+1
View File
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -NON_LOCAL_RETURN_NOT_ALLOWED
infix fun Function1<Int, Unit>.noInlineExt(p: Int) {}
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
infix fun Function1<Int, Unit>.noInlineExt(p: Int) {}
@@ -0,0 +1,12 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
fun main() {
test { }
}
<!NOTHING_TO_INLINE!>inline<!> fun (() -> Unit).call() {
invoke()
}
inline fun test(block: () -> Unit) {
<!USAGE_IS_NOT_INLINABLE!>block<!>.call()
}
@@ -0,0 +1,5 @@
package
public fun main(): kotlin.Unit
public inline fun test(/*0*/ block: () -> kotlin.Unit): kotlin.Unit
public inline fun (() -> kotlin.Unit).call(): kotlin.Unit
@@ -0,0 +1,11 @@
// !LANGUAGE: -ForbidExtensionCallsOnInlineFunctionalParameters
fun main() {
test { }
}
<!NOTHING_TO_INLINE!>inline<!> fun (() -> Unit).call() {
invoke()
}
inline fun test(block: () -> Unit) {
<!USAGE_IS_NOT_INLINABLE!>block<!>.call()
}
@@ -0,0 +1,11 @@
// !LANGUAGE: -ForbidExtensionCallsOnInlineFunctionalParameters
fun main() {
test { }
}
<!NOTHING_TO_INLINE!>inline<!> fun (() -> Unit).call() {
invoke()
}
inline fun test(block: () -> Unit) {
<!USAGE_IS_NOT_INLINABLE_WARNING!>block<!>.call()
}
@@ -0,0 +1,5 @@
package
public fun main(): kotlin.Unit
public inline fun test(/*0*/ block: () -> kotlin.Unit): kotlin.Unit
public inline fun (() -> kotlin.Unit).call(): kotlin.Unit
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED
inline operator fun <T, V> Function1<T, V>.unaryPlus() = this
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -VAL_REASSIGNMENT -UNUSED_CHANGED_VALUE -VARIABLE_EXPECTED
inline operator fun <T, V> Function1<T, V>.unaryPlus() = this
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
inline operator fun <T, V> Function1<T, V>.not() : Boolean {
return !this
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_COROUTINES
// SKIP_TXT
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// WITH_COROUTINES
// SKIP_TXT
@@ -1,4 +1,5 @@
// FIR_IDENTICAL
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// SKIP_TXT
// WITH_COROUTINES
@@ -1,3 +1,4 @@
// !LANGUAGE: +ForbidExtensionCallsOnInlineFunctionalParameters
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// SKIP_TXT
// WITH_COROUTINES
@@ -16932,6 +16932,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/inline/extensionOnFunction.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_after.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_after() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_after.kt");
}
@Test
@TestMetadata("forbidExtensionCallsOnInlineFunctionalParameters_before.kt")
public void testForbidExtensionCallsOnInlineFunctionalParameters_before() throws Exception {
runTest("compiler/testData/diagnostics/tests/inline/forbidExtensionCallsOnInlineFunctionalParameters_before.kt");
}
@Test
@TestMetadata("fromInlineToNoInline.kt")
public void testFromInlineToNoInline() throws Exception {
@@ -276,6 +276,7 @@ enum class LanguageFeature(
ReportTypeVarianceConflictOnQualifierArguments(KOTLIN_1_9, kind = BUG_FIX), // KT-50947
ReportErrorsOnRecursiveTypeInsidePlusAssignment(KOTLIN_1_9, kind = BUG_FIX), // KT-48546
ForbidInferringTypeVariablesIntoEmptyIntersection(KOTLIN_1_9, kind = BUG_FIX), // KT-51221
ForbidExtensionCallsOnInlineFunctionalParameters(KOTLIN_1_9, kind = BUG_FIX), // KT-52502
// Disabled for indefinite time. See KT-48535 and related discussion
ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null),