From 1ba8b5285674e71a29cfbbd97432de91d83b4988 Mon Sep 17 00:00:00 2001 From: Toshiaki Kameyama Date: Wed, 22 Jan 2020 19:01:31 +0900 Subject: [PATCH] Constructor parameter is never used as a property: do not report if parameter is used as a reference #KT-34686 Fixed --- .../kotlin/idea/inspections/CanBeParameterInspection.kt | 2 +- idea/testData/inspections/canBeParameter/test.kt | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt index 9a1a04e6048..b704ca4f1cf 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/CanBeParameterInspection.kt @@ -99,7 +99,7 @@ class CanBeParameterInspection : AbstractKotlinInspection() { // Find all references and check them val references = ReferencesSearch.search(parameter, restrictedScope) if (references.none()) return - if (references.any { it.usedAsPropertyIn(klass) }) return + if (references.any { it.element.parent is KtCallableReferenceExpression || it.usedAsPropertyIn(klass) }) return holder.registerProblem( valOrVar, "Constructor parameter is never used as a property", diff --git a/idea/testData/inspections/canBeParameter/test.kt b/idea/testData/inspections/canBeParameter/test.kt index b08515f4daf..a9c9ccc93a8 100644 --- a/idea/testData/inspections/canBeParameter/test.kt +++ b/idea/testData/inspections/canBeParameter/test.kt @@ -151,3 +151,8 @@ class UsedInObjectSuper(val bar456: String) { object : Base1(bar456) {} } } + +// NO +class Foo(var baz: String) { + var bar = ::baz +} \ No newline at end of file