[NI] Report error about non-spread parameter from arguments mapper
This commit is contained in:
+6
-6
@@ -113,11 +113,6 @@ class DiagnosticReporterByTrackingStrategy(
|
||||
VarargArgumentOutsideParentheses::class.java ->
|
||||
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 ->
|
||||
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) {
|
||||
|
||||
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) {
|
||||
|
||||
+1
-1
@@ -240,7 +240,7 @@ class ArgumentsToParametersMapper {
|
||||
}
|
||||
else {
|
||||
if (resolvedArgument.callArgument.isSpread) {
|
||||
addDiagnostic(NonVarargSpread(resolvedArgument.callArgument, parameter))
|
||||
addDiagnostic(NonVarargSpread(resolvedArgument.callArgument))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
-13
@@ -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() {
|
||||
override fun KotlinResolutionCandidate.process(workIndex: Int) {
|
||||
assert(kotlinCall.argumentsInParenthesis.isEmpty()) {
|
||||
|
||||
+1
-7
@@ -33,7 +33,7 @@ abstract class InapplicableArgumentDiagnostic : KotlinCallDiagnostic(INAPPLICABL
|
||||
// ArgumentsToParameterMapper
|
||||
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)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
class NoneCandidatesCallDiagnostic(val kotlinCall: KotlinCall) : KotlinCallDiagnostic(INAPPLICABLE) {
|
||||
override fun report(reporter: DiagnosticReporter) {
|
||||
|
||||
+1
-2
@@ -183,8 +183,7 @@ enum class KotlinCallKind(vararg resolutionPart: ResolutionPart) {
|
||||
CheckExplicitReceiverKindConsistency,
|
||||
CheckReceivers,
|
||||
CheckArguments,
|
||||
CheckExternalArgument,
|
||||
CheckSpreadArgumentToNonVarargParameter
|
||||
CheckExternalArgument
|
||||
),
|
||||
UNSUPPORTED();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user