diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java index 025e21b53a4..c0229b896e0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/Errors.java @@ -566,6 +566,7 @@ public interface Errors { DiagnosticFactory1 NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING); DiagnosticFactory2 USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR); DiagnosticFactory2 NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR); + DiagnosticFactory2 RECURSION_IN_INLINE = DiagnosticFactory2.create(ERROR); DiagnosticFactory0 DECLARATION_CANT_BE_INLINED = DiagnosticFactory0.create(ERROR); // Error sets diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java index 641210646f8..0bb7936120f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/diagnostics/rendering/DefaultErrorMessages.java @@ -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(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(RECURSION_IN_INLINE, "Inline-function ''{1}'' couldn't be recursive", ELEMENT_TEXT, TO_STRING); MAP.setImmutable(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java index 660a777b18c..ab6e425943f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/InlineCallResolverExtension.java @@ -97,6 +97,7 @@ public class InlineCallResolverExtension implements CallResolverExtension { } checkVisibility(targetDescriptor, expression, context); + checkRecursion(targetDescriptor, expression, context); } 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) { JetType type = descriptor.getReturnType(); return type != null && diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.kt index b369662aad8..4b23809b753 100644 --- a/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.kt +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/contains.kt @@ -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 Function1.contains(p: Function1): Boolean { this in p p in this diff --git a/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.kt b/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.kt index 0688d4bbd1c..de45b3d7cdd 100644 --- a/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.kt +++ b/compiler/testData/diagnostics/tests/inline/binaryExpressions/rangeTo.kt @@ -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 Function1.rangeTo(p: Function1): Range { this..p diff --git a/compiler/testData/diagnostics/tests/inline/recursion.kt b/compiler/testData/diagnostics/tests/inline/recursion.kt new file mode 100644 index 00000000000..58fde2562b3 --- /dev/null +++ b/compiler/testData/diagnostics/tests/inline/recursion.kt @@ -0,0 +1,23 @@ +// !DIAGNOSTICS: -NOTHING_TO_INLINE -UNUSED_PARAMETER -UNUSED_VARIABLE -NOTHING_TO_INLINE -VARIABLE_EXPECTED + +inline fun inlineFun(s: (p: Int) -> Unit) { + inlineFun(s) +} + +inline fun inlineFun(s: T) { + inlineFun(11) +} + + +inline fun Function0.inlineExt() { + ({11}:Function0).inlineExt(); + {11}.inlineExt() +} + +inline fun Function1.not() : Boolean { + return !this +} + +inline fun Function1.inc() : Function1 { + return this++ +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt index 51933f30698..5585da9b664 100644 --- a/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt +++ b/compiler/testData/diagnostics/tests/inline/unaryExpressions/notOperation.kt @@ -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 Function1.not() : Boolean { return !this } diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 7ca738c6881..6b215ab9ee1 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -3822,6 +3822,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage 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") public void testReturns() throws Exception { doTest("compiler/testData/diagnostics/tests/inline/returns.kt");