Checking modality and visibility of inline function
This commit is contained in:
+19
-3
@@ -17,9 +17,7 @@
|
||||
package org.jetbrains.jet.lang.resolve.extension;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
@@ -43,6 +41,7 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
||||
"This method should be invoced on inline function: " + descriptor;
|
||||
|
||||
checkDefaults(descriptor, function, trace);
|
||||
checkModality(descriptor, function, trace);
|
||||
|
||||
JetVisitorVoid visitor = new JetVisitorVoid() {
|
||||
|
||||
@@ -86,4 +85,21 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkModality(
|
||||
@NotNull FunctionDescriptor functionDescriptor,
|
||||
@NotNull JetFunction function,
|
||||
@NotNull BindingTrace trace
|
||||
) {
|
||||
if (functionDescriptor.getVisibility() == Visibilities.PRIVATE || functionDescriptor.getModality() == Modality.FINAL) {
|
||||
return;
|
||||
}
|
||||
|
||||
DeclarationDescriptor declaration = functionDescriptor.getContainingDeclaration();
|
||||
if (declaration instanceof NamespaceDescriptor) {
|
||||
return;
|
||||
}
|
||||
|
||||
trace.report(Errors.DECLARATION_CANT_BE_INLINED.on(function));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
inline private fun a() {}
|
||||
|
||||
inline fun b() {}
|
||||
|
||||
inline public fun c() {}
|
||||
|
||||
abstract class A {
|
||||
inline private fun good1() {}
|
||||
inline public final fun good2() {}
|
||||
inline protected final fun good3() {}
|
||||
inline final fun good4() {}
|
||||
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open protected fun wrong1() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open public fun wrong2() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open fun wrong3() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline abstract protected fun wrong4()<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline abstract public fun wrong5()<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline abstract fun wrong6()<!>
|
||||
}
|
||||
|
||||
|
||||
trait B {
|
||||
|
||||
inline private fun good1() {}
|
||||
inline public final fun good2() {}
|
||||
inline protected final fun good3() {}
|
||||
inline final fun good4() {}
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline fun wrong1() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open protected fun wrong2() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open public fun wrong3() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline open fun wrong4() {}<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline protected fun wrong5()<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline public fun wrong6()<!>
|
||||
|
||||
<!DECLARATION_CANT_BE_INLINED!>inline fun wrong7()<!>
|
||||
}
|
||||
@@ -3782,6 +3782,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/inline/invoke.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nonVirtualMembersWithInline.kt")
|
||||
public void testNonVirtualMembersWithInline() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/nonVirtualMembersWithInline.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("propagation.kt")
|
||||
public void testPropagation() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/inline/propagation.kt");
|
||||
|
||||
Reference in New Issue
Block a user