Nothing to inline diagnostic
This commit is contained in:
+28
@@ -22,6 +22,8 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.FunctionAnalyzerExtension;
|
||||
import org.jetbrains.jet.lang.types.lang.InlineUtil;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -42,6 +44,7 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
||||
|
||||
checkDefaults(descriptor, function, trace);
|
||||
checkModality(descriptor, function, trace);
|
||||
checkHashInlinable(descriptor, function, trace);
|
||||
|
||||
JetVisitorVoid visitor = new JetVisitorVoid() {
|
||||
|
||||
@@ -102,4 +105,29 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
||||
|
||||
trace.report(Errors.DECLARATION_CANT_BE_INLINED.on(function));
|
||||
}
|
||||
|
||||
private void checkHashInlinable(
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull JetFunction function,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
List<ValueParameterDescriptor> parameters = functionDescriptor.getValueParameters();
|
||||
for (ValueParameterDescriptor parameter : parameters) {
|
||||
KotlinBuiltIns builtIns = KotlinBuiltIns.getInstance();
|
||||
if (builtIns.isExactFunctionOrExtensionFunctionType(parameter.getType())) {
|
||||
if (!InlineUtil.hasNoinlineAnnotation(parameter)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
ReceiverParameterDescriptor receiverParameter = functionDescriptor.getReceiverParameter();
|
||||
if (receiverParameter != null) {
|
||||
if (KotlinBuiltIns.getInstance().isExactFunctionOrExtensionFunctionType(receiverParameter.getType())) {
|
||||
//or extension on inlinable function
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
trace.report(Errors.NOTHING_TO_INLINE.on(function, functionDescriptor));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
fun Function1<Int, Unit>.noInlineExt(p: Int) {}
|
||||
|
||||
@@ -48,4 +48,4 @@ inline fun inlineFunWrongExtension(s: (p: Int) -> Unit) {
|
||||
{
|
||||
<!USAGE_IS_NOT_INLINABLE!>s<!>.noInlineExt(11)
|
||||
} ()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
fun Function1<Int, Unit>.noInlineExt(p: Int) {}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {
|
||||
s(11)
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
inline private fun a() {}
|
||||
|
||||
inline fun b() {}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NULLABLE_INLINE_PARAMETER
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun test() {
|
||||
|
||||
}<!>
|
||||
|
||||
inline fun test2(s : (Int) -> Int) {
|
||||
|
||||
}
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun test3(noinline s : (Int) -> Int) {
|
||||
|
||||
}<!>
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun test4(noinline s : Int.() -> Int) {
|
||||
|
||||
}<!>
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun Function1<Int, Int>?.test5() {
|
||||
|
||||
}<!>
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun Function1<Int, Int>?.test6() {
|
||||
|
||||
}<!>
|
||||
|
||||
<!NOTHING_TO_INLINE!>inline fun test2(s : ((Int) -> Int)?) {
|
||||
|
||||
}<!>
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
inline fun inlineFunWithInvoke(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {
|
||||
subInline(s, ext)
|
||||
@@ -34,4 +34,4 @@ inline fun Function1<Int, Unit>.inlineExtWithClosure(ext: Int.(p: Int) -> Unit)
|
||||
|
||||
inline fun subInline(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {}
|
||||
|
||||
fun subNoInline(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {}
|
||||
fun subNoInline(s: (p: Int) -> Unit, ext: Int.(p: Int) -> Unit) {}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
inline fun unsupported() {
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE
|
||||
|
||||
inline fun inlineFun(s: (p: Int) -> Unit, noinline b: (p: Int) -> Unit) {
|
||||
subInline(<!USAGE_IS_NOT_INLINABLE!>s<!>, b)
|
||||
|
||||
@@ -3787,6 +3787,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nothingToInline.kt")
|
||||
public void testNothingToInline() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/nothingToInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propagation.kt")
|
||||
public void testPropagation() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/propagation.kt");
|
||||
|
||||
Reference in New Issue
Block a user