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 c0e05acd658..b271ff7b015 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/DiagnosticReporterByTrackingStrategy.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2016 JetBrains s.r.o. + * Copyright 2010-2017 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ package org.jetbrains.kotlin.resolve.calls import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.diagnostics.Errors.* -import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.* +import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.INVOKE_ON_FUNCTION_TYPE +import org.jetbrains.kotlin.diagnostics.Errors.BadNamedArgumentsTarget.NON_KOTLIN_FUNCTION import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext import org.jetbrains.kotlin.resolve.calls.inference.model.* import org.jetbrains.kotlin.resolve.calls.model.* @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver class DiagnosticReporterByTrackingStrategy( val constantExpressionEvaluator: ConstantExpressionEvaluator, val context: BasicCallResolutionContext, - val trace: BindingTrace, + val trace: TrackingBindingTrace, val psiKotlinCall: PSIKotlinCall ): DiagnosticReporter { private val tracingStrategy: TracingStrategy get() = psiKotlinCall.tracingStrategy @@ -104,8 +104,10 @@ class DiagnosticReporterByTrackingStrategy( val nameReference = callArgument.psiCallArgument.valueArgument.getArgumentName()?.referenceExpression ?: error("Argument name should be not null for argument: $callArgument") when (diagnostic.javaClass) { - NamedArgumentReference::class.java -> + NamedArgumentReference::class.java -> { trace.record(BindingContext.REFERENCE_TARGET, nameReference, (diagnostic as NamedArgumentReference).parameterDescriptor) + trace.markAsReported() + } NameForAmbiguousParameter::class.java -> trace.report(NAME_FOR_AMBIGUOUS_PARAMETER.on(nameReference)) NameNotFound::class.java -> trace.report(NAMED_PARAMETER_NOT_FOUND.on(nameReference, nameReference)) @@ -130,6 +132,7 @@ class DiagnosticReporterByTrackingStrategy( SmartCastManager.checkAndRecordPossibleCast( dataFlowValue, smartCastDiagnostic.smartCastType, argumentExpression, context, call, recordExpressionType = true) + trace.markAsReported() } else if(expressionArgument is ReceiverExpressionKotlinCallArgument) { val receiverValue = expressionArgument.receiver.receiverValue @@ -137,6 +140,7 @@ class DiagnosticReporterByTrackingStrategy( SmartCastManager.checkAndRecordPossibleCast( dataFlowValue, smartCastDiagnostic.smartCastType, (receiverValue as? ExpressionReceiver)?.expression, context, call, recordExpressionType = true) + trace.markAsReported() } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt index e91f8792126..17b25e2943c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/KotlinToResolvedCallTransformer.kt @@ -342,19 +342,13 @@ class KotlinToResolvedCallTransformer( trace: BindingTrace, completedCall: CompletedKotlinCall.Simple ) { - var reported: Boolean - val reportTrackedTrace = object : BindingTrace by trace { - override fun report(diagnostic: Diagnostic) { - trace.report(diagnostic) - reported = true - } - } - val diagnosticReporter = DiagnosticReporterByTrackingStrategy(constantExpressionEvaluator, context, reportTrackedTrace, completedCall.kotlinCall.psiKotlinCall) + val trackingTrace = TrackingBindingTrace(trace) + val diagnosticReporter = DiagnosticReporterByTrackingStrategy(constantExpressionEvaluator, context, trackingTrace, completedCall.kotlinCall.psiKotlinCall) for (diagnostic in completedCall.resolutionStatus.diagnostics) { - reported = false + trackingTrace.reported = false diagnostic.report(diagnosticReporter) - if (!reported && REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC) { + if (!trackingTrace.reported && REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC) { val factory = if (diagnostic.candidateApplicability.isSuccess) Errors.NEW_INFERENCE_DIAGNOSTIC else Errors.NEW_INFERENCE_ERROR trace.report(factory.on(diagnosticReporter.psiKotlinCall.psiCall.callElement, "Missing diagnostic: $diagnostic")) } @@ -362,6 +356,19 @@ class KotlinToResolvedCallTransformer( } } +class TrackingBindingTrace(val trace: BindingTrace) : BindingTrace by trace { + var reported: Boolean = false + + override fun report(diagnostic: Diagnostic) { + trace.report(diagnostic) + reported = true + } + + fun markAsReported() { + reported = true + } +} + sealed class NewAbstractResolvedCall(): ResolvedCall { abstract val argumentMappingByOriginal: Map abstract val kotlinCall: KotlinCall