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 (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)) {
|
if (declaration is KtCallableDeclaration && declaration.canBeHandledByLightMethods(descriptor)) {
|
||||||
val lightMethods = declaration.toLightMethods()
|
val lightMethods = declaration.toLightMethods()
|
||||||
if (lightMethods.isNotEmpty()) {
|
if (lightMethods.isNotEmpty()) {
|
||||||
@@ -396,13 +403,8 @@ class UnusedSymbolInspection : AbstractKotlinInspection() {
|
|||||||
|
|
||||||
if (declaration is KtEnumEntry) {
|
if (declaration is KtEnumEntry) {
|
||||||
val enumClass = declaration.containingClass()?.takeIf { it.isEnum() }
|
val enumClass = declaration.containingClass()?.takeIf { it.isEnum() }
|
||||||
if (enumClass != null && ReferencesSearch.search(
|
if (enumClass != null
|
||||||
KotlinReferencesSearchParameters(
|
&& ReferencesSearch.search(KotlinReferencesSearchParameters(enumClass, useScope)).any(::hasBuiltInEnumFunctionReference)
|
||||||
enumClass,
|
|
||||||
useScope,
|
|
||||||
kotlinOptions = searchOptions
|
|
||||||
)
|
|
||||||
).any(::hasBuiltInEnumFunctionReference)
|
|
||||||
) return true
|
) 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");
|
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")
|
@TestMetadata("secondaryLocalClassConstructor.kt")
|
||||||
public void testSecondaryLocalClassConstructor() throws Exception {
|
public void testSecondaryLocalClassConstructor() throws Exception {
|
||||||
runTest("idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt");
|
runTest("idea/testData/inspectionsLocal/unusedSymbol/secondaryLocalClassConstructor.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user