Do not report unused parameters for actual constructors
Extract common part for functions and constructors in processUnusedParameter
This commit is contained in:
@@ -649,16 +649,17 @@ class ControlFlowInformationProvider private constructor(
|
||||
}
|
||||
|
||||
private fun processUnusedParameter(ctxt: VariableUseContext, element: KtParameter, variableDescriptor: VariableDescriptor) {
|
||||
val functionDescriptor = variableDescriptor.containingDeclaration as FunctionDescriptor
|
||||
|
||||
if (functionDescriptor.isExpect || functionDescriptor.isActual ||
|
||||
functionDescriptor.isEffectivelyExternal() ||
|
||||
!diagnosticSuppressor.shouldReportUnusedParameter(variableDescriptor)) return
|
||||
|
||||
val owner = element.parent.parent
|
||||
when (owner) {
|
||||
is KtPrimaryConstructor -> if (!element.hasValOrVar()) {
|
||||
val containingClass = owner.getContainingClassOrObject()
|
||||
val containingClassDescriptor = trace.get(DECLARATION_TO_DESCRIPTOR, containingClass) as? ClassDescriptor
|
||||
if (!DescriptorUtils.isAnnotationClass(containingClassDescriptor) &&
|
||||
containingClassDescriptor?.isExpect == false &&
|
||||
!containingClassDescriptor.isEffectivelyExternal() &&
|
||||
diagnosticSuppressor.shouldReportUnusedParameter(variableDescriptor)
|
||||
) {
|
||||
val containingClass = (functionDescriptor as ConstructorDescriptor).containingDeclaration
|
||||
if (!DescriptorUtils.isAnnotationClass(containingClass)) {
|
||||
report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt)
|
||||
}
|
||||
}
|
||||
@@ -669,19 +670,13 @@ class ControlFlowInformationProvider private constructor(
|
||||
}
|
||||
val mainFunctionDetector = MainFunctionDetector(trace.bindingContext)
|
||||
val isMain = owner is KtNamedFunction && mainFunctionDetector.isMain(owner)
|
||||
val functionDescriptor =
|
||||
trace.get(DECLARATION_TO_DESCRIPTOR, owner) as? FunctionDescriptor
|
||||
?: throw AssertionError(owner.text)
|
||||
val functionName = functionDescriptor.name
|
||||
if (isMain
|
||||
|| functionDescriptor.isOverridableOrOverrides
|
||||
|| owner.hasModifier(KtTokens.OVERRIDE_KEYWORD)
|
||||
|| functionDescriptor.isExpect || functionDescriptor.isActual
|
||||
|| functionDescriptor.isEffectivelyExternal()
|
||||
|| OperatorNameConventions.GET_VALUE == functionName
|
||||
|| OperatorNameConventions.SET_VALUE == functionName
|
||||
|| OperatorNameConventions.PROVIDE_DELEGATE == functionName
|
||||
|| !diagnosticSuppressor.shouldReportUnusedParameter(variableDescriptor)) {
|
||||
|| OperatorNameConventions.PROVIDE_DELEGATE == functionName) {
|
||||
return
|
||||
}
|
||||
if (anonymous) {
|
||||
@@ -1116,4 +1111,4 @@ class ControlFlowInformationProvider private constructor(
|
||||
|| diagnosticFactory === UNUSED_ANONYMOUS_PARAMETER
|
||||
|| diagnosticFactory === UNUSED_CHANGED_VALUE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -12,6 +12,7 @@ expect class Bar3()
|
||||
expect class Bar4()
|
||||
expect class Bar5()
|
||||
expect class Bar6()
|
||||
expect class Bar7(s: String)
|
||||
|
||||
// MODULE: m2-jvm(m1-common)
|
||||
|
||||
@@ -48,3 +49,7 @@ actual class Bar5 {
|
||||
class <!ACTUAL_MISSING!>Bar6<!> {
|
||||
actual constructor()
|
||||
}
|
||||
|
||||
actual class Bar7 actual constructor(s: String) {
|
||||
constructor() : this("")
|
||||
}
|
||||
|
||||
+15
@@ -43,6 +43,13 @@ public final expect class Bar6 {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final expect class Bar7 {
|
||||
public constructor Bar7(/*0*/ s: kotlin.String)
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final expect class Foo1 {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
@@ -105,6 +112,14 @@ public final class Bar6 {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final actual class Bar7 {
|
||||
public constructor Bar7()
|
||||
public constructor Bar7(/*0*/ s: kotlin.String)
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final actual class Foo1 {
|
||||
public constructor Foo1(/*0*/ s: kotlin.String)
|
||||
public final val s: kotlin.String
|
||||
|
||||
Reference in New Issue
Block a user