False positive "unused constructor" for local class

#KT-30637 Fixed
This commit is contained in:
Dmitry Gridin
2019-03-27 13:32:47 +07:00
parent 0b94aa4be2
commit 5802928e52
6 changed files with 39 additions and 1 deletions
@@ -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()
@@ -0,0 +1,10 @@
// PROBLEM: none
// WITH_RUNTIME
fun main() {
class LocalClass(val number: Int) {
<caret>constructor(s: String) : this(s.toInt())
}
val l = LocalClass("42")
}
@@ -0,0 +1,8 @@
// "Safe delete constructor" "true"
fun main() {
class LocalClass(val number: Int) {
<caret>constructor(s: String) : this(s.toInt())
}
val l = LocalClass(42)
}
@@ -0,0 +1,7 @@
// "Safe delete constructor" "true"
fun main() {
class LocalClass(val number: Int) {
}
val l = LocalClass(42)
}
@@ -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");
@@ -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");