[NI] Report deprecation for function from companion in NI.
This commit is contained in:
+7
@@ -375,6 +375,13 @@ class KotlinToResolvedCallTransformer(
|
|||||||
trackingTrace.reported = false
|
trackingTrace.reported = false
|
||||||
diagnostic.report(diagnosticReporter)
|
diagnostic.report(diagnosticReporter)
|
||||||
|
|
||||||
|
if (diagnostic is ResolvedUsingDeprecatedVisibility) {
|
||||||
|
reportResolvedUsingDeprecatedVisibility(
|
||||||
|
completedCallAtom.atom.psiKotlinCall.psiCall, completedCallAtom.candidateDescriptor,
|
||||||
|
resultingDescriptor, diagnostic, trace
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
val dontRecordToTraceAsIs = diagnostic is ResolutionDiagnostic && diagnostic !is VisibilityError
|
val dontRecordToTraceAsIs = diagnostic is ResolutionDiagnostic && diagnostic !is VisibilityError
|
||||||
val shouldReportMissingDiagnostic = !trackingTrace.reported && !dontRecordToTraceAsIs
|
val shouldReportMissingDiagnostic = !trackingTrace.reported && !dontRecordToTraceAsIs
|
||||||
if (shouldReportMissingDiagnostic && REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC) {
|
if (shouldReportMissingDiagnostic && REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC) {
|
||||||
|
|||||||
+48
-34
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.psi.Call
|
import org.jetbrains.kotlin.psi.Call
|
||||||
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
import org.jetbrains.kotlin.psi.KtReferenceExpression
|
||||||
import org.jetbrains.kotlin.resolve.BindingContext
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.DeprecationResolver
|
import org.jetbrains.kotlin.resolve.DeprecationResolver
|
||||||
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
import org.jetbrains.kotlin.resolve.TemporaryBindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
import org.jetbrains.kotlin.resolve.calls.CallTransformer
|
||||||
@@ -305,41 +306,11 @@ class NewResolutionOldInference(
|
|||||||
// return@map null
|
// return@map null
|
||||||
}
|
}
|
||||||
|
|
||||||
is ResolvedUsingDeprecatedVisbility -> {
|
is ResolvedUsingDeprecatedVisibility -> {
|
||||||
resolvedCall.trace.record(
|
reportResolvedUsingDeprecatedVisibility(
|
||||||
BindingContext.DEPRECATED_SHORT_NAME_ACCESS,
|
resolvedCall.call, resolvedCall.candidateDescriptor,
|
||||||
resolvedCall.call.calleeExpression
|
resolvedCall.resultingDescriptor, error, resolvedCall.trace
|
||||||
)
|
)
|
||||||
|
|
||||||
val candidateDescriptor = resolvedCall.candidateDescriptor
|
|
||||||
val descriptorToLookup: DeclarationDescriptor = when (candidateDescriptor) {
|
|
||||||
is ClassConstructorDescriptor -> candidateDescriptor.containingDeclaration
|
|
||||||
is FakeCallableDescriptorForObject -> candidateDescriptor.classDescriptor
|
|
||||||
else -> error(
|
|
||||||
"Unexpected candidate descriptor of resolved call with " +
|
|
||||||
"ResolvedUsingDeprecatedVisibility-diagnostic: $candidateDescriptor\n" +
|
|
||||||
"Call context: ${resolvedCall.call.callElement.parent?.text}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If this descriptor was resolved from HierarchicalScope, then there can be another, non-deprecated path
|
|
||||||
// in parents of base scope
|
|
||||||
val sourceScope = error.baseSourceScope
|
|
||||||
val canBeResolvedWithoutDeprecation = if (sourceScope is HierarchicalScope) {
|
|
||||||
descriptorToLookup.canBeResolvedWithoutDeprecation(
|
|
||||||
sourceScope,
|
|
||||||
error.lookupLocation
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
// Normally, that should be unreachable, but instead of asserting that, we will report diagnostic
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!canBeResolvedWithoutDeprecation) {
|
|
||||||
resolvedCall.trace.report(
|
|
||||||
Errors.DEPRECATED_ACCESS_BY_SHORT_NAME.on(resolvedCall.call.callElement, resolvedCall.resultingDescriptor)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -609,3 +580,46 @@ internal fun createPreviousResolveError(status: ResolutionStatus): PreviousResol
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val BasicCallResolutionContext.isSuperCall: Boolean get() = call.explicitReceiver is SuperCallReceiverValue
|
private val BasicCallResolutionContext.isSuperCall: Boolean get() = call.explicitReceiver is SuperCallReceiverValue
|
||||||
|
|
||||||
|
internal fun reportResolvedUsingDeprecatedVisibility(
|
||||||
|
call: Call,
|
||||||
|
candidateDescriptor: CallableDescriptor,
|
||||||
|
resultingDescriptor : CallableDescriptor,
|
||||||
|
diagnostic: ResolvedUsingDeprecatedVisibility,
|
||||||
|
trace: BindingTrace
|
||||||
|
) {
|
||||||
|
trace.record(
|
||||||
|
BindingContext.DEPRECATED_SHORT_NAME_ACCESS,
|
||||||
|
call.calleeExpression
|
||||||
|
)
|
||||||
|
|
||||||
|
val descriptorToLookup: DeclarationDescriptor = when (candidateDescriptor) {
|
||||||
|
is ClassConstructorDescriptor -> candidateDescriptor.containingDeclaration
|
||||||
|
is FakeCallableDescriptorForObject -> candidateDescriptor.classDescriptor
|
||||||
|
else -> error(
|
||||||
|
"Unexpected candidate descriptor of resolved call with " +
|
||||||
|
"ResolvedUsingDeprecatedVisibility-diagnostic: $candidateDescriptor\n" +
|
||||||
|
"Call context: ${call.callElement.parent?.text}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If this descriptor was resolved from HierarchicalScope, then there can be another, non-deprecated path
|
||||||
|
// in parents of base scope
|
||||||
|
val sourceScope = diagnostic.baseSourceScope
|
||||||
|
val canBeResolvedWithoutDeprecation = if (sourceScope is HierarchicalScope) {
|
||||||
|
descriptorToLookup.canBeResolvedWithoutDeprecation(
|
||||||
|
sourceScope,
|
||||||
|
diagnostic.lookupLocation
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
// Normally, that should be unreachable, but instead of asserting that, we will report diagnostic
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!canBeResolvedWithoutDeprecation) {
|
||||||
|
trace.report(
|
||||||
|
Errors.DEPRECATED_ACCESS_BY_SHORT_NAME.on(call.callElement, resultingDescriptor)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+1
-1
@@ -109,4 +109,4 @@ object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(CONVENTION_
|
|||||||
object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR)
|
object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR)
|
||||||
object DeprecatedUnaryPlusAsPlus : ResolutionDiagnostic(CONVENTION_ERROR)
|
object DeprecatedUnaryPlusAsPlus : ResolutionDiagnostic(CONVENTION_ERROR)
|
||||||
|
|
||||||
class ResolvedUsingDeprecatedVisbility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED)
|
class ResolvedUsingDeprecatedVisibility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED)
|
||||||
@@ -239,7 +239,7 @@ internal open class ScopeBasedTowerLevel protected constructor(
|
|||||||
createCandidateDescriptor(
|
createCandidateDescriptor(
|
||||||
classifier,
|
classifier,
|
||||||
dispatchReceiver = null,
|
dispatchReceiver = null,
|
||||||
specialError = if (isDeprecated) ResolvedUsingDeprecatedVisbility(resolutionScope, location) else null
|
specialError = if (isDeprecated) ResolvedUsingDeprecatedVisibility(resolutionScope, location) else null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,7 +259,7 @@ internal open class ScopeBasedTowerLevel protected constructor(
|
|||||||
createCandidateDescriptor(
|
createCandidateDescriptor(
|
||||||
it,
|
it,
|
||||||
dispatchReceiver = null,
|
dispatchReceiver = null,
|
||||||
specialError = ResolvedUsingDeprecatedVisbility(resolutionScope, location)
|
specialError = ResolvedUsingDeprecatedVisibility(resolutionScope, location)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user