Unused symbol: do not report for secondary constructor when class is used as typealias
#KT-20907 Fixed
This commit is contained in:
committed by
Vladimir Dolzhenko
parent
81f1f441fc
commit
3398683093
@@ -383,6 +383,13 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
if (referenceUsed) return true
|
||||
}
|
||||
|
||||
if (declaration is KtSecondaryConstructor) {
|
||||
val containingClass = declaration.containingClass()
|
||||
if (containingClass != null && ReferencesSearch.search(KotlinReferencesSearchParameters(containingClass, useScope)).any {
|
||||
it.element.getStrictParentOfType<KtTypeAlias>() != null
|
||||
}) return true
|
||||
}
|
||||
|
||||
if (declaration is KtCallableDeclaration && declaration.canBeHandledByLightMethods(descriptor)) {
|
||||
val lightMethods = declaration.toLightMethods()
|
||||
if (lightMethods.isNotEmpty()) {
|
||||
@@ -396,13 +403,8 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
||||
|
||||
if (declaration is KtEnumEntry) {
|
||||
val enumClass = declaration.containingClass()?.takeIf { it.isEnum() }
|
||||
if (enumClass != null && ReferencesSearch.search(
|
||||
KotlinReferencesSearchParameters(
|
||||
enumClass,
|
||||
useScope,
|
||||
kotlinOptions = searchOptions
|
||||
)
|
||||
).any(::hasBuiltInEnumFunctionReference)
|
||||
if (enumClass != null
|
||||
&& ReferencesSearch.search(KotlinReferencesSearchParameters(enumClass, useScope)).any(::hasBuiltInEnumFunctionReference)
|
||||
) return true
|
||||
}
|
||||
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// PROBLEM: none
|
||||
class A(x: Double) {
|
||||
<caret>constructor(i: Int) : this(i.toDouble())
|
||||
}
|
||||
|
||||
class C {
|
||||
val a = B(1)
|
||||
}
|
||||
|
||||
typealias B = A
|
||||
+5
@@ -13064,6 +13064,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/unusedSymbol/propertyOfInlineClassType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("secondaryConstructorCalledByTypeAlias.kt")
|
||||
public void testSecondaryConstructorCalledByTypeAlias() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/unusedSymbol/secondaryConstructorCalledByTypeAlias.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("secondaryLocalClassConstructor.kt")
|
||||
public void testSecondaryLocalClassConstructor() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt");
|
||||
|
||||
Reference in New Issue
Block a user