diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt index 3f14ab7062a..2958189202e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/UnusedSymbolInspection.kt @@ -399,7 +399,10 @@ class UnusedSymbolInspection : AbstractKotlinInspection() { private fun KtCallableDeclaration.canBeHandledByLightMethods(descriptor: DeclarationDescriptor?): Boolean { return when { - descriptor is ConstructorDescriptor -> !descriptor.constructedClass.isInline + descriptor is ConstructorDescriptor -> { + val classDescriptor = descriptor.constructedClass + !classDescriptor.isInline && classDescriptor.visibility != Visibilities.LOCAL + } hasModifier(KtTokens.INTERNAL_KEYWORD) -> false descriptor !is FunctionDescriptor -> true else -> !descriptor.hasInlineClassParameters() diff --git a/idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt b/idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt new file mode 100644 index 00000000000..d9b7ac9dc99 --- /dev/null +++ b/idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt @@ -0,0 +1,10 @@ +// PROBLEM: none +// WITH_RUNTIME + +fun main() { + class LocalClass(val number: Int) { + constructor(s: String) : this(s.toInt()) + } + + val l = LocalClass("42") +} \ No newline at end of file diff --git a/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt b/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt new file mode 100644 index 00000000000..11c0d374832 --- /dev/null +++ b/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt @@ -0,0 +1,8 @@ +// "Safe delete constructor" "true" +fun main() { + class LocalClass(val number: Int) { + constructor(s: String) : this(s.toInt()) + } + + val l = LocalClass(42) +} \ No newline at end of file diff --git a/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt.after b/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt.after new file mode 100644 index 00000000000..c5dca47cc0b --- /dev/null +++ b/idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt.after @@ -0,0 +1,7 @@ +// "Safe delete constructor" "true" +fun main() { + class LocalClass(val number: Int) { + } + + val l = LocalClass(42) +} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java index e86dde6672b..cb090a1fadd 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java @@ -8728,6 +8728,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest { runTest("idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt"); } + @TestMetadata("secondaryLocalClassConstructor.kt") + public void testSecondaryLocalClassConstructor() throws Exception { + runTest("idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt"); + } + @TestMetadata("typeAlias.kt") public void testTypeAlias() throws Exception { runTest("idea/testData/inspectionsLocal/unusedSymbol/typeAlias.kt"); diff --git a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java index 5eee92bfd9d..4da562a8f2f 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/quickfix/QuickFixTestGenerated.java @@ -10121,6 +10121,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest { runTest("idea/testData/quickfix/removeUnused/notTriangle.kt"); } + @TestMetadata("secondaryLocalClassConstructor.kt") + public void testSecondaryLocalClassConstructor() throws Exception { + runTest("idea/testData/quickfix/removeUnused/secondaryLocalClassConstructor.kt"); + } + @TestMetadata("simpleUnusedEnumEntry.kt") public void testSimpleUnusedEnumEntry() throws Exception { runTest("idea/testData/quickfix/removeUnused/simpleUnusedEnumEntry.kt");