[NI] Don't report NI error for recorded info about smartcasts

This commit is contained in:
Mikhail Zarechenskiy
2017-07-13 14:26:19 +03:00
parent 64b722d4f6
commit 5486f4e612
2 changed files with 26 additions and 15 deletions
@@ -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()
}
}
@@ -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<D : CallableDescriptor>(): ResolvedCall<D> {
abstract val argumentMappingByOriginal: Map<ValueParameterDescriptor, ResolvedCallArgument>
abstract val kotlinCall: KotlinCall