[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
This commit is contained in:
+11
-7
@@ -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<ExpressionKotlinCallArgumentImpl>()?.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 <T> 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")
|
||||
|
||||
Reference in New Issue
Block a user