Introduce UNUSED_ANONYMOUS_PARAMETER for anonymous functions

It is not reported for 1.0 language version because
renaming to _ is not possible. It has weak warning severity

So #KT-8813 Fixed
So #KT-16875 Fixed
This commit is contained in:
Mikhail Glukhikh
2017-03-30 17:42:46 +03:00
parent 110fc103de
commit 7a53b2f4c8
65 changed files with 130 additions and 90 deletions
@@ -646,8 +646,8 @@ class ControlFlowInformationProvider private constructor(
}
}
is KtFunction -> {
if (owner is KtFunctionLiteral &&
!languageVersionSettings.supportsFeature(LanguageFeature.SingleUnderscoreForParameterName)) {
val anonymous = owner is KtFunctionLiteral || owner is KtNamedFunction && owner.name == null
if (anonymous && !languageVersionSettings.supportsFeature(LanguageFeature.SingleUnderscoreForParameterName)) {
return
}
val mainFunctionDetector = MainFunctionDetector(trace.bindingContext)
@@ -666,7 +666,12 @@ class ControlFlowInformationProvider private constructor(
|| OperatorNameConventions.PROVIDE_DELEGATE == functionName) {
return
}
report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt)
if (anonymous) {
report(UNUSED_ANONYMOUS_PARAMETER.on(element, variableDescriptor), ctxt)
}
else {
report(UNUSED_PARAMETER.on(element, variableDescriptor), ctxt)
}
}
}
}
@@ -1121,6 +1126,7 @@ class ControlFlowInformationProvider private constructor(
private fun mustBeReportedOnAllCopies(diagnosticFactory: DiagnosticFactory<*>) =
diagnosticFactory === UNUSED_VARIABLE
|| diagnosticFactory === UNUSED_PARAMETER
|| diagnosticFactory === UNUSED_ANONYMOUS_PARAMETER
|| diagnosticFactory === UNUSED_CHANGED_VALUE
}
}
@@ -744,6 +744,7 @@ public interface Errors {
DiagnosticFactory1<KtNamedDeclaration, VariableDescriptor> UNUSED_VARIABLE = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtParameter, VariableDescriptor> UNUSED_PARAMETER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtParameter, VariableDescriptor> UNUSED_ANONYMOUS_PARAMETER = DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory1<KtDestructuringDeclarationEntry, VariableDescriptor> UNUSED_DESTRUCTURED_PARAMETER_ENTRY =
DiagnosticFactory1.create(WARNING, DECLARATION_NAME);
DiagnosticFactory2<KtTypeParameter, TypeParameterDescriptor, KotlinType> UNUSED_TYPEALIAS_PARAMETER =
@@ -288,6 +288,7 @@ public class DefaultErrorMessages {
MAP.put(UNINITIALIZED_ENUM_COMPANION, "Companion object of enum class ''{0}'' is uninitialized here", NAME);
MAP.put(UNUSED_VARIABLE, "Variable ''{0}'' is never used", NAME);
MAP.put(UNUSED_PARAMETER, "Parameter ''{0}'' is never used", NAME);
MAP.put(UNUSED_ANONYMOUS_PARAMETER, "Parameter ''{0}'' is never used, could be renamed to _", NAME);
MAP.put(UNUSED_DESTRUCTURED_PARAMETER_ENTRY, "Destructured parameter ''{0}'' is never used", NAME);
MAP.put(ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, "Variable ''{0}'' is assigned but never accessed", NAME);
MAP.put(VARIABLE_WITH_REDUNDANT_INITIALIZER, "Variable ''{0}'' initializer is redundant", NAME);