[NI] Report error about non-spread parameter from arguments mapper

This commit is contained in:
Mikhail Zarechenskiy
2017-11-14 13:00:14 +03:00
parent 13ee0f8eda
commit f3ef961be6
5 changed files with 9 additions and 29 deletions
@@ -113,11 +113,6 @@ class DiagnosticReporterByTrackingStrategy(
VarargArgumentOutsideParentheses::class.java -> VarargArgumentOutsideParentheses::class.java ->
reportIfNonNull(callArgument.psiExpression) { trace.report(VARARG_OUTSIDE_PARENTHESES.on(it)) } reportIfNonNull(callArgument.psiExpression) { trace.report(VARARG_OUTSIDE_PARENTHESES.on(it)) }
SpreadArgumentToNonVarargParameter::class.java -> {
val spreadElement = callArgument.safeAs<ExpressionKotlinCallArgumentImpl>()?.valueArgument?.getSpreadElement()
reportIfNonNull(spreadElement) { trace.report(NON_VARARG_SPREAD.on(it)) }
}
MixingNamedAndPositionArguments::class.java -> MixingNamedAndPositionArguments::class.java ->
trace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(callArgument.psiCallArgument.valueArgument.asElement())) trace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(callArgument.psiCallArgument.valueArgument.asElement()))
} }
@@ -147,7 +142,12 @@ class DiagnosticReporterByTrackingStrategy(
} }
override fun onCallArgumentSpread(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) { override fun onCallArgumentSpread(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) {
when (diagnostic.javaClass) {
NonVarargSpread::class.java -> {
val spreadElement = callArgument.safeAs<ExpressionKotlinCallArgumentImpl>()?.valueArgument?.getSpreadElement()
reportIfNonNull(spreadElement) { trace.report(NON_VARARG_SPREAD.on(it)) }
}
}
} }
private fun reportSmartCast(smartCastDiagnostic: SmartCastDiagnostic) { private fun reportSmartCast(smartCastDiagnostic: SmartCastDiagnostic) {
@@ -240,7 +240,7 @@ class ArgumentsToParametersMapper {
} }
else { else {
if (resolvedArgument.callArgument.isSpread) { if (resolvedArgument.callArgument.isSpread) {
addDiagnostic(NonVarargSpread(resolvedArgument.callArgument, parameter)) addDiagnostic(NonVarargSpread(resolvedArgument.callArgument))
} }
} }
} }
@@ -109,19 +109,6 @@ internal object ArgumentsToCandidateParameterDescriptor : ResolutionPart() {
} }
} }
internal object CheckSpreadArgumentToNonVarargParameter : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) {
for ((_, resolvedCallArgument) in resolvedCall.argumentMappingByOriginal) {
for (argument in resolvedCallArgument.arguments) {
val valueParameter = resolvedCall.argumentToCandidateParameter[argument] ?: continue
if (argument.isSpread && !valueParameter.isVararg) {
addDiagnostic(SpreadArgumentToNonVarargParameter(argument))
}
}
}
}
}
internal object NoArguments : ResolutionPart() { internal object NoArguments : ResolutionPart() {
override fun KotlinResolutionCandidate.process(workIndex: Int) { override fun KotlinResolutionCandidate.process(workIndex: Int) {
assert(kotlinCall.argumentsInParenthesis.isEmpty()) { assert(kotlinCall.argumentsInParenthesis.isEmpty()) {
@@ -33,7 +33,7 @@ abstract class InapplicableArgumentDiagnostic : KotlinCallDiagnostic(INAPPLICABL
// ArgumentsToParameterMapper // ArgumentsToParameterMapper
class TooManyArguments(override val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : InapplicableArgumentDiagnostic() class TooManyArguments(override val argument: KotlinCallArgument, val descriptor: CallableDescriptor) : InapplicableArgumentDiagnostic()
class NonVarargSpread (val argument: KotlinCallArgument, val parameterDescriptor: ValueParameterDescriptor) : KotlinCallDiagnostic(INAPPLICABLE) { class NonVarargSpread(val argument: KotlinCallArgument) : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentSpread(argument, this) override fun report(reporter: DiagnosticReporter) = reporter.onCallArgumentSpread(argument, this)
} }
@@ -162,12 +162,6 @@ class SuperAsExtensionReceiver(val receiver: SimpleKotlinCallArgument) : KotlinC
} }
} }
class SpreadArgumentToNonVarargParameter(val argument: KotlinCallArgument) : KotlinCallDiagnostic(RUNTIME_ERROR) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCallArgument(argument, this)
}
}
// candidates result // candidates result
class NoneCandidatesCallDiagnostic(val kotlinCall: KotlinCall) : KotlinCallDiagnostic(INAPPLICABLE) { class NoneCandidatesCallDiagnostic(val kotlinCall: KotlinCall) : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) { override fun report(reporter: DiagnosticReporter) {
@@ -183,8 +183,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
CheckExplicitReceiverKindConsistency, CheckExplicitReceiverKindConsistency,
CheckReceivers, CheckReceivers,
CheckArguments, CheckArguments,
CheckExternalArgument, CheckExternalArgument
CheckSpreadArgumentToNonVarargParameter
), ),
UNSUPPORTED(); UNSUPPORTED();