Inline recursion diagnostic
This commit is contained in:
@@ -566,6 +566,7 @@ public interface Errors {
|
|||||||
DiagnosticFactory1<JetElement, DeclarationDescriptor> NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING);
|
DiagnosticFactory1<JetElement, DeclarationDescriptor> NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING);
|
||||||
DiagnosticFactory2<JetElement, JetExpression, DeclarationDescriptor> USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<JetElement, JetExpression, DeclarationDescriptor> USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR);
|
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR);
|
||||||
|
DiagnosticFactory2<JetElement, JetElement, DeclarationDescriptor> RECURSION_IN_INLINE = DiagnosticFactory2.create(ERROR);
|
||||||
DiagnosticFactory0<JetElement> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetElement> DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
// Error sets
|
// Error sets
|
||||||
|
|||||||
+1
@@ -479,6 +479,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(NOTHING_TO_INLINE, "There are no parameters of Function types to be inlined in ''{0}''", TO_STRING);
|
MAP.put(NOTHING_TO_INLINE, "There are no parameters of Function types to be inlined in ''{0}''", TO_STRING);
|
||||||
MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Annotate the parameter with [noinline]", ELEMENT_TEXT, TO_STRING);
|
MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Annotate the parameter with [noinline]", ELEMENT_TEXT, TO_STRING);
|
||||||
MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Annotate the parameter with [noinline] or make not nullable", ELEMENT_TEXT, TO_STRING);
|
MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Annotate the parameter with [noinline] or make not nullable", ELEMENT_TEXT, TO_STRING);
|
||||||
|
MAP.put(RECURSION_IN_INLINE, "Inline-function ''{1}'' couldn't be recursive", ELEMENT_TEXT, TO_STRING);
|
||||||
|
|
||||||
MAP.setImmutable();
|
MAP.setImmutable();
|
||||||
|
|
||||||
|
|||||||
+11
@@ -97,6 +97,7 @@ public class InlineCallResolverExtension implements CallResolverExtension {
|
|||||||
}
|
}
|
||||||
|
|
||||||
checkVisibility(targetDescriptor, expression, context);
|
checkVisibility(targetDescriptor, expression, context);
|
||||||
|
checkRecursion(targetDescriptor, expression, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean couldAccessVariable(JetExpression expression) {
|
private static boolean couldAccessVariable(JetExpression expression) {
|
||||||
@@ -199,6 +200,16 @@ public class InlineCallResolverExtension implements CallResolverExtension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void checkRecursion(
|
||||||
|
@NotNull CallableDescriptor targetDescriptor,
|
||||||
|
@NotNull JetElement expression,
|
||||||
|
@NotNull BasicCallResolutionContext context
|
||||||
|
) {
|
||||||
|
if (targetDescriptor.getOriginal() == descriptor) {
|
||||||
|
context.trace.report(Errors.RECURSION_IN_INLINE.on(expression, expression, descriptor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
|
private static boolean isInlinableParameter(@NotNull CallableDescriptor descriptor) {
|
||||||
JetType type = descriptor.getReturnType();
|
JetType type = descriptor.getReturnType();
|
||||||
return type != null &&
|
return type != null &&
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
|
||||||
inline fun <T, U> Function1<T, U>.contains(p: Function1<T, U>): Boolean {
|
inline fun <T, U> Function1<T, U>.contains(p: Function1<T, U>): Boolean {
|
||||||
this in p
|
this in p
|
||||||
p in this
|
p in this
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
|
||||||
|
|
||||||
inline fun <T, U> Function1<T, U>.rangeTo(p: Function1<T, U>): Range<Int> {
|
inline fun <T, U> Function1<T, U>.rangeTo(p: Function1<T, U>): Range<Int> {
|
||||||
this..p
|
this..p
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -VARIABLE_EXPECTED
|
||||||
|
|
||||||
|
inline fun inlineFun(s: (p: Int) -> Unit) {
|
||||||
|
<!RECURSION_IN_INLINE!>inlineFun<!>(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T> inlineFun(s: T) {
|
||||||
|
<!RECURSION_IN_INLINE!>inlineFun<!><Int>(11)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
inline fun <T> Function0<T>.inlineExt() {
|
||||||
|
({11}:Function0<Int>).<!RECURSION_IN_INLINE!>inlineExt<!>();
|
||||||
|
{11}.<!RECURSION_IN_INLINE!>inlineExt<!>()
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T, V> Function1<T, V>.not() : Boolean {
|
||||||
|
return <!RECURSION_IN_INLINE!>!<!>this
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun <T, V> Function1<T, V>.inc() : Function1<T, V> {
|
||||||
|
return this<!RECURSION_IN_INLINE!>++<!>
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE
|
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -RECURSION_IN_INLINE
|
||||||
inline fun <T, V> Function1<T, V>.not() : Boolean {
|
inline fun <T, V> Function1<T, V>.not() : Boolean {
|
||||||
return !this
|
return !this
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3822,6 +3822,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/inline/propagation.kt");
|
doTest("compiler/testData/diagnostics/tests/inline/propagation.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("recursion.kt")
|
||||||
|
public void testRecursion() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/inline/recursion.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("returns.kt")
|
@TestMetadata("returns.kt")
|
||||||
public void testReturns() throws Exception {
|
public void testReturns() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/inline/returns.kt");
|
doTest("compiler/testData/diagnostics/tests/inline/returns.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user