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 f09bdbfe71a..ed7b66c3590 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 @@ -375,6 +375,13 @@ class KotlinToResolvedCallTransformer( trackingTrace.reported = false 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 shouldReportMissingDiagnostic = !trackingTrace.reported && !dontRecordToTraceAsIs if (shouldReportMissingDiagnostic && REPORT_MISSING_NEW_INFERENCE_DIAGNOSTIC) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index 6f64a896695..32f69d3ddce 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.Call import org.jetbrains.kotlin.psi.KtReferenceExpression import org.jetbrains.kotlin.resolve.BindingContext +import org.jetbrains.kotlin.resolve.BindingTrace import org.jetbrains.kotlin.resolve.DeprecationResolver import org.jetbrains.kotlin.resolve.TemporaryBindingTrace import org.jetbrains.kotlin.resolve.calls.CallTransformer @@ -305,41 +306,11 @@ class NewResolutionOldInference( // return@map null } - is ResolvedUsingDeprecatedVisbility -> { - resolvedCall.trace.record( - BindingContext.DEPRECATED_SHORT_NAME_ACCESS, - resolvedCall.call.calleeExpression + is ResolvedUsingDeprecatedVisibility -> { + reportResolvedUsingDeprecatedVisibility( + resolvedCall.call, resolvedCall.candidateDescriptor, + 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 + +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) + ) + } + +} \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index b72fbabaf84..c815a708095 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -109,4 +109,4 @@ object InvokeConventionCallNoOperatorModifier : ResolutionDiagnostic(CONVENTION_ object InfixCallNoInfixModifier : ResolutionDiagnostic(CONVENTION_ERROR) object DeprecatedUnaryPlusAsPlus : ResolutionDiagnostic(CONVENTION_ERROR) -class ResolvedUsingDeprecatedVisbility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED) \ No newline at end of file +class ResolvedUsingDeprecatedVisibility(val baseSourceScope: ResolutionScope, val lookupLocation: LookupLocation) : ResolutionDiagnostic(RESOLVED) \ No newline at end of file diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index af02b3de633..f1881355eed 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -239,7 +239,7 @@ internal open class ScopeBasedTowerLevel protected constructor( createCandidateDescriptor( classifier, 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( it, dispatchReceiver = null, - specialError = ResolvedUsingDeprecatedVisbility(resolutionScope, location) + specialError = ResolvedUsingDeprecatedVisibility(resolutionScope, location) ) } }