diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index aa11145880f..d6db2a8a59a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -646,8 +646,8 @@ class ControlFlowInformationProvider private constructor( } } is KtFunction -> { - if (owner is KtFunctionLiteral && - !languageVersionSettings.supportsFeature(LanguageFeature.SingleUnderscoreForParameterName)) { + val anonymous = owner is KtFunctionLiteral || owner is KtNamedFunction && owner.name == null + if (anonymous && !languageVersionSettings.supportsFeature(LanguageFeature.SingleUnderscoreForParameterName)) { return } val mainFunctionDetector = MainFunctionDetector(trace.bindingContext) @@ -666,7 +666,12 @@ class ControlFlowInformationProvider private constructor( || OperatorNameConventions.PROVIDE_DELEGATE == functionName) { return } - report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt) + if (anonymous) { + report(UNUSED_ANONYMOUS_PARAMETER.on(element, variableDescriptor), ctxt) + } + else { + report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt) + } } } } @@ -1121,6 +1126,7 @@ class ControlFlowInformationProvider private constructor( private fun mustBeReportedOnAllCopies(diagnosticFactory: DiagnosticFactory<*>) = diagnosticFactory === UNUSED_VARIABLE || diagnosticFactory === UNUSED_PARAMETER + || diagnosticFactory === UNUSED_ANONYMOUS_PARAMETER || diagnosticFactory === UNUSED_CHANGED_VALUE } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index e68f6baf0a5..c6c30cd29bc 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -744,6 +744,7 @@ public interface Errors { DiagnosticFactory1 UNUSED_VARIABLE = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); DiagnosticFactory1 UNUSED_PARAMETER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); + DiagnosticFactory1 UNUSED_ANONYMOUS_PARAMETER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); DiagnosticFactory1 UNUSED_DESTRUCTURED_PARAMETER_ENTRY = DiagnosticFactory1.create(WARNING, DECLARATION_NAME); DiagnosticFactory2 UNUSED_TYPEALIAS_PARAMETER = 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 85c3bfc08db..7d62691f23f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -288,6 +288,7 @@ public class DefaultErrorMessages { MAP.put(UNINITIALIZED_ENUM_COMPANION, "Companion object of enum class ''{0}'' is uninitialized here", NAME); MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME); MAP.put(UNUSED_PARAMETER, "Parameter ''{0}'' is never used", NAME); + MAP.put(UNUSED_ANONYMOUS_PARAMETER, "Parameter ''{0}'' is never used, could be renamed to _", NAME); MAP.put(UNUSED_DESTRUCTURED_PARAMETER_ENTRY, "Destructured parameter ''{0}'' is never used", NAME); MAP.put(ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, "Variable ''{0}'' is assigned but never accessed", NAME); MAP.put(VARIABLE_WITH_REDUNDANT_INITIALIZER, "Variable ''{0}'' initializer is redundant", NAME); diff --git a/compiler/testData/diagnostics/tests/AutoCreatedIt.kt b/compiler/testData/diagnostics/tests/AutoCreatedIt.kt index 3a2f3d93ffc..de250dc57c8 100644 --- a/compiler/testData/diagnostics/tests/AutoCreatedIt.kt +++ b/compiler/testData/diagnostics/tests/AutoCreatedIt.kt @@ -4,7 +4,7 @@ fun text() { "direct:a" on {it -> it.body == ""} to "mock:a" bar {1} bar {it + 1} - bar {it, it1 -> it} + bar {it, it1 -> it} bar1 {1} bar1 {it + 1} diff --git a/compiler/testData/diagnostics/tests/BacktickNames.kt b/compiler/testData/diagnostics/tests/BacktickNames.kt index 30d3a4dee67..020a9d9a86d 100644 --- a/compiler/testData/diagnostics/tests/BacktickNames.kt +++ b/compiler/testData/diagnostics/tests/BacktickNames.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER // TODO Uncomment all the examples when there will be no problems with light classes //package `foo.bar` diff --git a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt index 110885cc242..f082a178313 100644 --- a/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt +++ b/compiler/testData/diagnostics/tests/FunctionCalleeExpressions.kt @@ -36,8 +36,8 @@ fun main(args : Array) { foo2()({}) foo2(){} (foo2()){} - (foo2()){x -> } - foo2()({x -> }) + (foo2()){x -> } + foo2()({x -> }) val a = fooT1(1)() checkSubtype(a) @@ -72,7 +72,7 @@ fun main1() { } fun test() { - {x : Int -> 1}(); + {x : Int -> 1}(); (fun Int.() = 1)() "sd".(fun Int.() = 1)() val i : Int? = null diff --git a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.kt b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.kt index 6945941c99c..0b1d8f87a01 100644 --- a/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.kt +++ b/compiler/testData/diagnostics/tests/FunctionParameterWithoutType.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE fun test(a) { } diff --git a/compiler/testData/diagnostics/tests/ReserveYield2.kt b/compiler/testData/diagnostics/tests/ReserveYield2.kt index 2e579a30e1c..165989407f9 100644 --- a/compiler/testData/diagnostics/tests/ReserveYield2.kt +++ b/compiler/testData/diagnostics/tests/ReserveYield2.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION // FILE: 1.kt diff --git a/compiler/testData/diagnostics/tests/Underscore.kt b/compiler/testData/diagnostics/tests/Underscore.kt index 7327e54fc7a..0b66374cec2 100644 --- a/compiler/testData/diagnostics/tests/Underscore.kt +++ b/compiler/testData/diagnostics/tests/Underscore.kt @@ -14,7 +14,7 @@ fun __(___: Int, y: __________ - val q = fun(_: Int, __: Int) {} + val q = fun(_: Int, __: Int) {} q(1, 2) val _ = 56 diff --git a/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.kt b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.kt index 34467eba145..3cab4db96aa 100644 --- a/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.kt +++ b/compiler/testData/diagnostics/tests/annotations/onFunctionParameter.kt @@ -4,4 +4,4 @@ fun test(@ann p: Int) { } -val bar = fun(@ann g: Int) {} +val bar = fun(@ann g: Int) {} diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.kt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.kt new file mode 100644 index 00000000000..7495cd3595d --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.kt @@ -0,0 +1,9 @@ +// !LANGUAGE: -SingleUnderscoreForParameterName +// See KT-8813, KT-9631 + +fun someApi(f: (Int) -> Unit) = f(42) + +fun test() { + someApi(fun(p: Int) {}) + // Apparently "p" cannot be removed because the signature is fixed by "someApi +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.txt b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.txt new file mode 100644 index 00000000000..9f05f07e8b8 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.txt @@ -0,0 +1,4 @@ +package + +public fun someApi(/*0*/ f: (kotlin.Int) -> kotlin.Unit): kotlin.Unit +public fun test(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.kt index 182a0b8a7ca..899fa130d4c 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/anonymousFunAsLastExpressionInBlock.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE // !CHECK_TYPE fun foo(block: () -> (() -> Int)) {} diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt index 2ff0e612f2c..c7da3add29b 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE // !CHECK_TYPE fun foo(block: () -> (() -> Int)) {} diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt index 79866b22e2c..626893aaae0 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/AutoLabels.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE fun Iterable.map(transform: (T) -> R): List = null!! diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.kt b/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.kt index cf530e25af0..e7b9ef3c3a5 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/FunctionType.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE fun testReturnType(foo: String) { val bar = fun () = foo diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.kt b/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.kt index f45656b32ab..9a24fd7c65a 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/InferenceParametersTypes.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE fun listOf(): List = null!! fun test(a: (Int) -> Int) { diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.kt b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.kt index bf88e014f19..62d4dd0a1ee 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/MissingParameterTypes.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE val a = fun (x) = x diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.kt b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.kt index ebfac6efbcc..c5e7c90ab39 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/Parameters.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE val bar = fun(p: Int = 3) {} val bas = fun(vararg p: Int) {} diff --git a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.kt b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.kt index 74b74e8c350..f6cb5721cee 100644 --- a/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.kt +++ b/compiler/testData/diagnostics/tests/functionAsExpression/WithGenericParameters.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER interface A fun devNull(a: Any?){} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.kt b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.kt index aa2309c7e1e..9960a9dba67 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/DeprecatedSyntax.kt @@ -17,8 +17,8 @@ val none = { -> } val parameterWithFunctionType = { a: ((Int) -> Int) -> } // todo fix parser -val newSyntax = { a: Int -> } -val newSyntax1 = { a, b -> } -val newSyntax2 = { a: Int, b: Int -> } -val newSyntax3 = { a, b: Int -> } -val newSyntax4 = { a: Int, b -> } +val newSyntax = { a: Int -> } +val newSyntax1 = { a, b -> } +val newSyntax2 = { a: Int, b: Int -> } +val newSyntax3 = { a, b: Int -> } +val newSyntax4 = { a: Int, b -> } diff --git a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.kt b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.kt index f2d58801d68..a173e7acc79 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParameterTypeMismatchVariance.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER package a interface Super diff --git a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.kt b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.kt index c22d0ebdda4..8071686eb5b 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/ExpectedParametersTypesMismatch.kt @@ -9,20 +9,20 @@ fun test1() { "" } foo0 { - s: String-> "" + s: String-> "" } foo0 { - x, y -> "" + x, y -> "" } foo1 { "" } foo1 { - s: String -> "" + s: String -> "" } foo1 { - x, y -> "" + x, y -> "" } foo1 { -> 42 @@ -33,10 +33,10 @@ fun test1() { "" } foo2 { - s: String -> "" + s: String -> "" } foo2 { - x -> "" + x -> "" } foo2 { -> 42 diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.kt index 4422c7aa71d..20cc6a5b5ab 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/redeclaration.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER data class A(val x: Int, val y: String) data class B(val u: Double, val w: Short) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt index dd5af1b2368..62581e87574 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/destructuringInLambdas/unusedParameters.kt @@ -1,5 +1,5 @@ // !CHECK_TYPE -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER data class A(val x: Int, val y: String) data class B(val u: Double, val w: Short) diff --git a/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt index 8b1f31b0d4c..afcb91126c0 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/underscopeParameters.kt @@ -40,9 +40,9 @@ fun bar() { _ checkType { _() } } - foo { `_`, `_` -> + foo { `_`, `_` -> _ checkType { _() } } - foo(fun(x: Int, _: String) {}) + foo(fun(x: Int, _: String) {}) } diff --git a/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.kt b/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.kt index 663d2b3f00f..75900129d50 100644 --- a/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.kt +++ b/compiler/testData/diagnostics/tests/generics/projectionsScope/flexibleProjectedScope.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER // !CHECK_TYPE // FILE: Clazz.java diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.kt index 8baaf32bb96..19e634dab1a 100644 --- a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.kt +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveFunctionLiteralsNoUse.kt @@ -3,4 +3,4 @@ package f fun h(i: Int, a: Any, r: R, f: (Boolean) -> Int) = 1 fun h(a: Any, i: Int, r: R, f: (Boolean) -> Int) = 1 -fun test() = h(1, 1, 1, { b -> 42 }) +fun test() = h(1, 1, 1, { b -> 42 }) diff --git a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt index d8288f24031..dd918b55721 100644 --- a/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt +++ b/compiler/testData/diagnostics/tests/inference/cannotCompleteResolveWithFunctionLiterals.kt @@ -4,7 +4,7 @@ package f fun h(f: (Boolean) -> R) = 1 fun h(f: (String) -> R) = 2 -fun test() = h{ i -> getAnswer() } +fun test() = h{ i -> getAnswer() } fun getAnswer() = 42 diff --git a/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt index 3c085224cd1..e1ff62aaa50 100644 --- a/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt +++ b/compiler/testData/diagnostics/tests/inference/dependantOnVarianceNullable.kt @@ -5,7 +5,7 @@ import java.util.* import java.util.Collections.* fun foo(list: List) : String { - val w : String = max(list, comparator {o1, o2 -> 1 + val w : String = max(list, comparator {o1, o2 -> 1 }) return w } diff --git a/compiler/testData/diagnostics/tests/inference/kt6175.kt b/compiler/testData/diagnostics/tests/inference/kt6175.kt index 0f0ae20c175..2d6daec3357 100644 --- a/compiler/testData/diagnostics/tests/inference/kt6175.kt +++ b/compiler/testData/diagnostics/tests/inference/kt6175.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER fun foo(body: (R?) -> T): T = fail() diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt index 81b1c6e507f..772a0369995 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2283.kt @@ -9,5 +9,5 @@ fun Foo.map(f: (A) -> B): Foo = object : Foo fun foo() { val l: Foo = object : Foo {} - val m: Foo = l.map { ppp -> 1 } + val m: Foo = l.map { ppp -> 1 } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt index 2c7845f43f8..3134d451006 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2741.kt @@ -7,5 +7,5 @@ fun _arrayList(vararg values: T) : List = throw Ex class _Pair(val a: A) fun test() { - _arrayList(_Pair(1))._sortBy { it -> xxx } + _arrayList(_Pair(1))._sortBy { it -> xxx } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt index fdfb5762cc3..ff8fb60ad8c 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt2841.kt @@ -9,7 +9,7 @@ public inline fun T.use1(block: (T)-> R) : R { fun main(args: Array) { C().use1 { - w -> // ERROR here + w -> // ERROR here x } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3007.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3007.kt index 97cf4d55edd..ec96b685883 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt3007.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3007.kt @@ -8,7 +8,7 @@ enum class SomeEnum { // Doesn't work fun Iterable.some() { - this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> if (res == SomeEnum.FIRST) SomeEnum.FIRST else SomeEnum.SECOND }) } @@ -19,7 +19,7 @@ fun tempFun() : SomeEnum { // Doesn't work fun Iterable.someSimpleWithFun() { - this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> tempFun() }) } @@ -27,14 +27,14 @@ fun Iterable.someSimpleWithFun() { // Works fun Iterable.someSimple() { - this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> + this.fold(SomeEnum.FIRST, {res : SomeEnum, value -> SomeEnum.FIRST }) } // Works fun Iterable.someInt() { - this.fold(0, {res : Int, value -> + this.fold(0, {res : Int, value -> if (res == 0) 1 else 0 }) } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt index 4e00b72f47c..d8f9ec19425 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt3150.kt @@ -15,10 +15,10 @@ fun SomeTemplate.query(f: (i: Int) -> Unit) = f fun SomeTemplate.query1(f: (i: Int) -> Unit) = f fun test() { - val mapperFunction = { i: Int -> } + val mapperFunction = { i: Int -> } SomeTemplate().query(mapperFunction) // TYPE_MISMATCH: Required Class<[ERROR: CANT_INFER]>, Found (kotlin.Int) -> Unit - SomeTemplate().query { i: Int -> } - SomeTemplate().query1 { i: Int -> } + SomeTemplate().query { i: Int -> } + SomeTemplate().query1 { i: Int -> } } diff --git a/compiler/testData/diagnostics/tests/inference/regressions/kt8132.kt b/compiler/testData/diagnostics/tests/inference/regressions/kt8132.kt index 03aa63118db..6304e603450 100644 --- a/compiler/testData/diagnostics/tests/inference/regressions/kt8132.kt +++ b/compiler/testData/diagnostics/tests/inference/regressions/kt8132.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER // KT-8132 Can't omit lambda parameter types fun test(foo: List): T { diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.kt index 51ca71634e0..782ab51ee80 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/ErrorTypeAsGenericParameter.kt @@ -3,7 +3,7 @@ package a fun foo(block: (T)-> R, second: (T)-> S) = block fun main(args: Array) { - val fff = { x: Int -> aaa } + val fff = { x: Int -> aaa } foo(fff, { x -> x + 1 }) } diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt index a9097b1fbb5..0cb1b6c2dbf 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/NoAmbiguityForDifferentFunctionTypes.kt @@ -9,7 +9,7 @@ fun T.foo(block: (T, T)-> R) = block fun main(args: Array) { C().foo { // no ambiguity here - www -> + www -> xs } } diff --git a/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.kt b/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.kt index e628ec731b5..00f08e35c7a 100644 --- a/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.kt +++ b/compiler/testData/diagnostics/tests/inference/reportingImprovements/cannotInferParameterTypeWithInference.kt @@ -4,7 +4,7 @@ fun foo(block: (T)-> R) = block fun test1() { foo { - x -> // here we have 'cannot infer parameter type' error + x -> // here we have 'cannot infer parameter type' error 43 } } @@ -12,5 +12,5 @@ fun test1() { fun bar(f: (A)->Unit) {} fun test2() { - bar { a -> } // here we don't have 'cannot infer parameter type' error + bar { a -> } // here we don't have 'cannot infer parameter type' error } diff --git a/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.kt b/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.kt index 536868a44d5..544d981203a 100644 --- a/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.kt +++ b/compiler/testData/diagnostics/tests/j+k/sam/typeInferenceOnSamAdapters.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER // FILE: A.java public class A { public void foo(K key, BiFunction remappingFunction) { diff --git a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.kt b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.kt index f1ee7c75ad7..8ae8eaaa41f 100644 --- a/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.kt +++ b/compiler/testData/diagnostics/tests/j+k/samByProjectedType/noAdapterBecuaseOfRecursiveUpperBound.kt @@ -16,12 +16,12 @@ public class A { // FILE: main.kt fun main() { A().foo { - x -> + x -> "" } A.bar { - x -> + x -> "" } } diff --git a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt index d79b78a3c00..6918bd69c88 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_ANONYMOUS_PARAMETER // FILE: A.java import java.util.Comparator; diff --git a/compiler/testData/diagnostics/tests/regressions/Jet124.kt b/compiler/testData/diagnostics/tests/regressions/Jet124.kt index 0f4751a555f..ff38a390e05 100644 --- a/compiler/testData/diagnostics/tests/regressions/Jet124.kt +++ b/compiler/testData/diagnostics/tests/regressions/Jet124.kt @@ -3,6 +3,6 @@ fun foo1() : (Int) -> Int = { x: Int -> x } fun foo() { val h : (Int) -> Int = foo1(); h(1) - val m : (Int) -> Int = {a : Int -> 1}//foo1() + val m : (Int) -> Int = {a : Int -> 1}//foo1() m(1) } diff --git a/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.kt b/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.kt index 813e63404ef..901f589de5d 100644 --- a/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.kt +++ b/compiler/testData/diagnostics/tests/resolve/invoke/invokeNonExtensionLambdaInContext.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER class C { fun f() {} diff --git a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.kt b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.kt index b088fc9fefc..aa8e182ca7b 100644 --- a/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.kt +++ b/compiler/testData/diagnostics/tests/syntheticExtensions/samAdapters/GenericClass.kt @@ -1,6 +1,6 @@ // FILE: KotlinFile.kt fun foo(javaClass: JavaClass): String { - return javaClass.doSomething("", 1) { s: String -> "" } + return javaClass.doSomething("", 1) { s: String -> "" } } // FILE: JavaClass.java diff --git a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt index 7a296977469..e45a3665d8e 100644 --- a/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt +++ b/compiler/testData/diagnostics/tests/when/whenAndLambdaWithExpectedType.kt @@ -12,13 +12,13 @@ val test2: (String) -> Boolean = val test3: (String) -> Boolean = when { - true -> { s -> true } + true -> { s -> true } else -> null!! } val test4: (String) -> Boolean = when { - true -> { s1, s2 -> true } + true -> { s1, s2 -> true } else -> null!! } diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt index 4ef4ead4421..85c458d796e 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/dynamicCallsWithLambdas.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER // !CHECK_TYPE fun test(d: dynamic) { diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt index 9b434ae7d72..161bf5dab35 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/noImpl.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER, -UNREACHABLE_CODE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER, -UNREACHABLE_CODE val prop: String = definedExternally diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt index 3ff47f32ea4..ac3a3bf7baf 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER import kotlin.properties.Delegates class My { diff --git a/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.kt b/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.kt index b830323693d..416a48e121f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/annotations/Volatile.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER import kotlin.jvm.Volatile import kotlin.properties.Delegates diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.kt index 716c9a30460..e1f848efb73 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/inference/withUninferredParameter.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE class GenericController { suspend fun yield(t: T) {} diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt index c4e016f423d..d6c138e74dc 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/forbidden.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER import kotlin.coroutines.experimental.* import kotlin.coroutines.experimental.intrinsics.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt index 3c3c0d77d60..5bf72ee8526 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/tryCatch.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER import kotlin.coroutines.experimental.* import kotlin.coroutines.experimental.intrinsics.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt index 2ba804fe8cc..8d21ea13b81 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/tailCalls/valid.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER import kotlin.coroutines.experimental.* import kotlin.coroutines.experimental.intrinsics.* diff --git a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt index 3b6e10c9403..170a7e70064 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/functionLiterals/pseudocodeMemoryOverhead.kt @@ -33,8 +33,8 @@ private val STRING = CompileTimeType() private val ANY = CompileTimeType() -private val emptyBinaryFun: Function2 = { a, b -> BigInteger("0") } -private val emptyUnaryFun: Function1 = { a -> 1.toLong() } +private val emptyBinaryFun: Function2 = { a, b -> BigInteger("0") } +private val emptyUnaryFun: Function1 = { a -> 1.toLong() } private val unaryOperations: HashMap, Pair, Function1>> = hashMapOf, Pair, Function1>>( diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.kt index 40256400225..4ef22fc44b2 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/ea70485_functionTypeInheritor.kt @@ -4,7 +4,7 @@ class O : Function2 { } fun test() { - val a = fun(o: O) { + val a = fun(o: O) { } a {} } diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 77a6529d85c..72d237a2cae 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -4048,6 +4048,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("unusedInAnonymous.kt") + public void testUnusedInAnonymous() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/unusedInAnonymous.kt"); + doTest(fileName); + } + @TestMetadata("useUninitializedInLambda.kt") public void testUseUninitializedInLambda() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlFlowAnalysis/useUninitializedInLambda.kt"); diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt index c74e4f26b8d..73f8822613f 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/highlighter/KotlinPsiChecker.kt @@ -239,11 +239,16 @@ private class ElementAnnotator(private val element: PsiElement, AnnotationPresentationInfo( ranges, - textAttributes = if (factory == Errors.DEPRECATION) CodeInsightColors.DEPRECATED_ATTRIBUTES else null, - highlightType = if (factory in Errors.UNUSED_ELEMENT_DIAGNOSTICS) - ProblemHighlightType.LIKE_UNUSED_SYMBOL - else - null + textAttributes = when (factory) { + Errors.DEPRECATION -> CodeInsightColors.DEPRECATED_ATTRIBUTES + Errors.UNUSED_ANONYMOUS_PARAMETER -> CodeInsightColors.WEAK_WARNING_ATTRIBUTES + else -> null + }, + highlightType = when (factory) { + in Errors.UNUSED_ELEMENT_DIAGNOSTICS -> ProblemHighlightType.LIKE_UNUSED_SYMBOL + Errors.UNUSED_ANONYMOUS_PARAMETER -> ProblemHighlightType.WEAK_WARNING + else -> null + } ) } Severity.INFO -> return // Do nothing @@ -278,14 +283,22 @@ private class AnnotationPresentationInfo( val ranges: List, val nonDefaultMessage: String? = null, val highlightType: ProblemHighlightType? = null, - val textAttributes: TextAttributesKey? = null) { + val textAttributes: TextAttributesKey? = null +) { fun create(diagnostic: Diagnostic, range: TextRange, holder: AnnotationHolder): Annotation { val defaultMessage = nonDefaultMessage ?: getDefaultMessage(diagnostic) val annotation = when (diagnostic.severity) { Severity.ERROR -> holder.createErrorAnnotation(range, defaultMessage) - Severity.WARNING -> holder.createWarningAnnotation(range, defaultMessage) + Severity.WARNING -> { + if (highlightType == ProblemHighlightType.WEAK_WARNING) { + holder.createWeakWarningAnnotation(range, defaultMessage) + } + else { + holder.createWarningAnnotation(range, defaultMessage) + } + } else -> throw IllegalArgumentException("Only ERROR and WARNING diagnostics are supported") } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt index ea758e85134..0c951f2eec2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/QuickFixRegistrar.kt @@ -284,8 +284,8 @@ class QuickFixRegistrar : QuickFixContributor { TOO_MANY_ARGUMENTS.registerFactory(ChangeFunctionSignatureFix) NO_VALUE_FOR_PARAMETER.registerFactory(ChangeFunctionSignatureFix) UNUSED_PARAMETER.registerFactory(RemoveUnusedFunctionParameterFix) - UNUSED_PARAMETER.registerFactory(RenameToUnderscoreFix.Factory) - UNUSED_PARAMETER.registerFactory(RemoveSingleLambdaParameterFix) + UNUSED_ANONYMOUS_PARAMETER.registerFactory(RenameToUnderscoreFix.Factory) + UNUSED_ANONYMOUS_PARAMETER.registerFactory(RemoveSingleLambdaParameterFix) EXPECTED_PARAMETERS_NUMBER_MISMATCH.registerFactory(ChangeFunctionLiteralSignatureFix) EXPECTED_PARAMETER_TYPE_MISMATCH.registerFactory(ChangeTypeFix) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameToUnderscoreFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameToUnderscoreFix.kt index 914e40b680d..38cc6fdd91a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameToUnderscoreFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RenameToUnderscoreFix.kt @@ -36,7 +36,7 @@ class RenameToUnderscoreFix(element: KtCallableDeclaration) : KotlinQuickFixActi companion object Factory : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { val declaration: KtCallableDeclaration? = when (diagnostic.factory) { - Errors.UNUSED_PARAMETER -> { + Errors.UNUSED_ANONYMOUS_PARAMETER -> { val parameter = diagnostic.psiElement as? KtParameter val owner = parameter?.parent?.parent diff --git a/idea/testData/checker/regression/Jet124.kt b/idea/testData/checker/regression/Jet124.kt index 9e24d258511..6fa400a1acc 100644 --- a/idea/testData/checker/regression/Jet124.kt +++ b/idea/testData/checker/regression/Jet124.kt @@ -3,6 +3,6 @@ fun foo1() : (Int) -> Int = { x: Int -> x } fun foo() { val h : (Int) -> Int = foo1(); h(1) - val m : (Int) -> Int = {a : Int -> 1}//foo1() + val m : (Int) -> Int = {a : Int -> 1}//foo1() m(1) } diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/noReturnType.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/noReturnType.kt index 45e6ee408e2..9191cf2eb5e 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/noReturnType.kt +++ b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/noReturnType.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FILE: Sam.java @SamWithReceiver diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithAnnotation.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithAnnotation.kt index 4597f9ee377..374bdb3fb52 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithAnnotation.kt +++ b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithAnnotation.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FILE: Sam.java @SamWithReceiver diff --git a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithoutAnnotation.kt b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithoutAnnotation.kt index bd47103f7fe..cbc1a3503f2 100644 --- a/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithoutAnnotation.kt +++ b/plugins/sam-with-receiver/sam-with-receiver-cli/testData/diagnostics/samWithoutAnnotation.kt @@ -1,4 +1,4 @@ -// !DIAGNOSTICS: -UNUSED_PARAMETER,-UNUSED_VARIABLE +// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER,-UNUSED_VARIABLE // FILE: Sam.java public interface Sam {