Do not report a warning on an inline function with a reified parameter

#KT-6273 Fixed
This commit is contained in:
Denis Zharkov
2014-11-20 12:39:48 +04:00
parent f7d1bc5931
commit 02be1063c1
11 changed files with 27 additions and 7 deletions
@@ -128,11 +128,21 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
hasInlinable |= checkInlinableParameter(receiverParameter, receiver, functionDescriptor, trace);
}
hasInlinable |= containsReifiedTypeParameters(functionDescriptor);
if (!hasInlinable) {
trace.report(Errors.NOTHING_TO_INLINE.on(function, functionDescriptor));
}
}
private static boolean containsReifiedTypeParameters(@NotNull FunctionDescriptor descriptor) {
for (TypeParameterDescriptor typeParameterDescriptor : descriptor.getTypeParameters()) {
if (typeParameterDescriptor.isReified()) return true;
}
return false;
}
public static boolean checkInlinableParameter(
@NotNull CallableDescriptor parameter,
@NotNull JetElement expression,
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun <reified T> T.plus(p: T): T = this
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun <reified T> f(): T = throw UnsupportedOperationException()
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun<T1, reified T2> bar(x: T1, y: T2): T2 = y
inline fun<reified R> foo(z: R): R = bar(1, z)
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER -NOT_YET_SUPPORTED_IN_INLINE
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOT_YET_SUPPORTED_IN_INLINE
inline fun<reified T> foo(x: T) {
fun<<!REIFIED_TYPE_PARAMETER_NO_INLINE!>reified<!> R> bar() {
@@ -0,0 +1,2 @@
inline fun <T1, T2, reified T3, T4> foo(): T3 = null!!
@@ -0,0 +1,3 @@
package
kotlin.inline() internal fun </*0*/ T1, /*1*/ T2, /*2*/ reified T3, /*3*/ T4> foo(): T3
@@ -1,4 +1,3 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE
fun <T> fail1(): Array<T> = <!TYPE_PARAMETER_AS_REIFIED!>Array<!>(1) { null!! }
fun <T> ok1(block: () -> Array<T>): Array<T> = block()
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_VARIABLE
// !DIAGNOSTICS: -UNUSED_VARIABLE
fun <T> foo() {
val x = <!TYPE_PARAMETER_AS_REIFIED!>arrayOfNulls<!><T>(5)
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE -REIFIED_TYPE_PARAMETER_NO_INLINE
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNREACHABLE_CODE -UNUSED_VARIABLE
inline fun<reified T> foo(block: () -> T): String = block().toString()
@@ -5597,6 +5597,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("inlineReified.kt")
public void testInlineReified() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inline/inlineReified.kt");
doTest(fileName);
}
@TestMetadata("invoke.kt")
public void testInvoke() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inline/invoke.kt");