diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index d16a49935a1..67673bacbb6 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -672,7 +672,7 @@ public interface Errors { DiagnosticFactory2 INVISIBLE_MEMBER_FROM_INLINE = DiagnosticFactory2.create(ERROR, CALL_ELEMENT); DiagnosticFactory3 NON_LOCAL_RETURN_NOT_ALLOWED = DiagnosticFactory3.create(ERROR, CALL_ELEMENT); DiagnosticFactory2 NOT_YET_SUPPORTED_IN_INLINE = DiagnosticFactory2.create(ERROR); - DiagnosticFactory1 NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING, DECLARATION_SIGNATURE); + 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); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index 81062d76eec..b6c9466180c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -622,14 +622,14 @@ public class DefaultErrorMessages { MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets"); //Inline - MAP.put(INVISIBLE_MEMBER_FROM_INLINE, "Cannot access effectively non-public-api ''{0}'' member from effectively public-api ''{1}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); - MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "''{0}'' construction not yet supported in inline functions", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); - MAP.put(DECLARATION_CANT_BE_INLINED, "Inline annotation could be present only on nonvirtual members (private or final)"); + MAP.put(INVISIBLE_MEMBER_FROM_INLINE, "Cannot access effectively non-public-API ''{0}'' member from effectively public-API ''{1}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); + MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "''{0}'' construction is not yet supported in inline functions", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); + MAP.put(DECLARATION_CANT_BE_INLINED, "''inline'' modifier is not allowed on virtual members. Only private or final members can be inlined"); MAP.put(NOTHING_TO_INLINE, "Expected performance impact of inlining ''{0}'' can be insignificant. Inlining works best for functions with lambda parameters", SHORT_NAMES_IN_TYPES); - MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Annotate the parameter with [noinline]", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); - 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, SHORT_NAMES_IN_TYPES); - MAP.put(RECURSION_IN_INLINE, "Inline-function ''{1}'' can't be recursive", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); - //Inline non Locals + MAP.put(USAGE_IS_NOT_INLINABLE, "Illegal usage of inline-parameter ''{0}'' in ''{1}''. Add ''noinline'' modifier to the parameter declaration", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); + MAP.put(NULLABLE_INLINE_PARAMETER, "Inline-parameter ''{0}'' of ''{1}'' must not be nullable. Add ''noinline'' modifier to the parameter declaration or make its type not nullable", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); + MAP.put(RECURSION_IN_INLINE, "Inline function ''{1}'' can't be recursive", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES); + //Inline non locals MAP.put(NON_LOCAL_RETURN_NOT_ALLOWED, "Can''t inline ''{0}'' here: it may contain non-local returns. Add ''crossinline'' modifier to parameter declaration ''{0}''", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES); MAP.put(INLINE_CALL_CYCLE, "The ''{0}'' invocation is a part of inline cycle", NAME); MAP.put(NON_LOCAL_RETURN_IN_DISABLED_INLINE, "Non-local returns are not allowed with inlining disabled"); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineAnalyzerExtension.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineAnalyzerExtension.java index 38c7eb9a5dd..82e1645fae5 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineAnalyzerExtension.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineAnalyzerExtension.java @@ -16,10 +16,12 @@ package org.jetbrains.kotlin.resolve.inline; +import com.intellij.psi.PsiElement; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.diagnostics.Errors; +import org.jetbrains.kotlin.lexer.JetTokens; import org.jetbrains.kotlin.psi.*; import org.jetbrains.kotlin.resolve.BindingTrace; import org.jetbrains.kotlin.resolve.DescriptorUtils; @@ -125,7 +127,10 @@ public class InlineAnalyzerExtension implements FunctionAnalyzerExtension.Analyz hasInlinable |= DescriptorUtils.containsReifiedTypeParameters(functionDescriptor); if (!hasInlinable) { - trace.report(Errors.NOTHING_TO_INLINE.on(function, functionDescriptor)); + JetModifierList modifierList = function.getModifierList(); + PsiElement inlineModifier = modifierList == null ? null : modifierList.getModifier(JetTokens.INLINE_KEYWORD); + PsiElement reportOn = inlineModifier == null ? function : inlineModifier; + trace.report(Errors.NOTHING_TO_INLINE.on(reportOn, functionDescriptor)); } } diff --git a/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.kt b/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.kt index 1b9df97e03b..a90db24b9d9 100644 --- a/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.kt +++ b/compiler/testData/diagnostics/tests/inline/fromInlineToNoInline.kt @@ -2,6 +2,6 @@ inline fun onlyLocal(p: () -> R) { inlineAll(p) } -inline fun inlineAll(noinline p: () -> R) { +inline fun inlineAll(noinline p: () -> R) { p() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.kt index 75114b6c56c..ef9a02850f6 100644 --- a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.kt +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsGeneric.kt @@ -6,6 +6,6 @@ fun box() : String { return "OK" } -inline fun test(p: T) { +inline fun test(p: T) { p.toString() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.kt b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.kt index 9d27da6a17e..6abdc96f9f0 100644 --- a/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.kt +++ b/compiler/testData/diagnostics/tests/inline/nonLocalReturns/lambdaAsNonFunction.kt @@ -6,6 +6,6 @@ fun box() : String { return "OK" } -inline fun test(p: Any) { +inline fun test(p: Any) { p.toString() } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nothingToInline.kt b/compiler/testData/diagnostics/tests/inline/nothingToInline.kt index 3b9d26c2519..0a4780dafbb 100644 --- a/compiler/testData/diagnostics/tests/inline/nothingToInline.kt +++ b/compiler/testData/diagnostics/tests/inline/nothingToInline.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE -NULLABLE_INLINE_PARAMETER -CONFLICTING_JVM_DECLARATIONS -inline fun test() { +inline fun test() { } @@ -8,22 +8,22 @@ inline fun test2(s : (Int) -> Int) { } -inline fun test3(noinline s : (Int) -> Int) { +inline fun test3(noinline s : (Int) -> Int) { } -inline fun test4(noinline s : Int.() -> Int) { +inline fun test4(noinline s : Int.() -> Int) { } -inline fun Function1?.test5() { +inline fun Function1?.test5() { } -inline fun Function1?.test6() { +inline fun Function1?.test6() { } -inline fun test2(s : ((Int) -> Int)?) { +inline fun test2(s : ((Int) -> Int)?) { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/inline/nullableFunction.kt b/compiler/testData/diagnostics/tests/inline/nullableFunction.kt index f9f5a3435a4..d4ff0463c3f 100644 --- a/compiler/testData/diagnostics/tests/inline/nullableFunction.kt +++ b/compiler/testData/diagnostics/tests/inline/nullableFunction.kt @@ -12,10 +12,10 @@ public inline fun submitNoInline(noinline action: Function1?, s: ( action?.invoke(10) } -public inline fun Function1?.submit() { +public inline fun Function1?.submit() { } -public inline fun submit(action: Function1?) { +public inline fun submit(action: Function1?) { } \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/native/inline.kt b/compiler/testData/diagnostics/testsWithStdLib/native/inline.kt index 54cb0fda2be..c5568c62db6 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/native/inline.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/native/inline.kt @@ -1,11 +1,11 @@ import kotlin.jvm.* abstract class C { - inline external fun foo() + inline external fun foo() } fun test() { abstract class Local { - inline external fun foo() + inline external fun foo() } } \ No newline at end of file