From 13ee0f8eda9f9a3f18564ec4643cd0b353975f9d Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Tue, 14 Nov 2017 11:37:50 +0300 Subject: [PATCH] [NI] Don't forget to report error about mixing different kinds of args Also use more safe way to report errors: only if there is corresponding PSI element. This is not very useful for compiler, but in IDE we can get synthetic calls with null psi arguments --- .../DiagnosticReporterByTrackingStrategy.kt | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt index a08312d4309..45f9242cab7 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -104,25 +104,29 @@ class DiagnosticReporterByTrackingStrategy( SmartCastDiagnostic::class.java -> reportSmartCast(diagnostic as SmartCastDiagnostic) UnstableSmartCast::class.java -> reportUnstableSmartCast(diagnostic as UnstableSmartCast) TooManyArguments::class.java -> { - val psiExpression = callArgument.psiExpression - if (psiExpression != null) { - trace.report(TOO_MANY_ARGUMENTS.on(psiExpression, (diagnostic as TooManyArguments).descriptor)) + reportIfNonNull(callArgument.psiExpression) { + trace.report(TOO_MANY_ARGUMENTS.on(it, (diagnostic as TooManyArguments).descriptor)) } trace.markAsReported() } VarargArgumentOutsideParentheses::class.java -> - trace.report(VARARG_OUTSIDE_PARENTHESES.on(callArgument.psiExpression!!)) + reportIfNonNull(callArgument.psiExpression) { trace.report(VARARG_OUTSIDE_PARENTHESES.on(it)) } SpreadArgumentToNonVarargParameter::class.java -> { val spreadElement = callArgument.safeAs()?.valueArgument?.getSpreadElement() - if (spreadElement != null) { - trace.report(NON_VARARG_SPREAD.on(spreadElement)) - } + reportIfNonNull(spreadElement) { trace.report(NON_VARARG_SPREAD.on(it)) } } + + MixingNamedAndPositionArguments::class.java -> + trace.report(MIXING_NAMED_AND_POSITIONED_ARGUMENTS.on(callArgument.psiCallArgument.valueArgument.asElement())) } } + private fun reportIfNonNull(element: T?, report: (T) -> Unit) { + if (element != null) report(element) + } + override fun onCallArgumentName(callArgument: KotlinCallArgument, diagnostic: KotlinCallDiagnostic) { val nameReference = callArgument.psiCallArgument.valueArgument.getArgumentName()?.referenceExpression ?: error("Argument name should be not null for argument: $callArgument")