Fix presence of Deprecated hidden annotation for reference arguments

#KT-40234 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2020-07-13 01:42:19 +03:00
parent c2e0cd60d7
commit 678b76cab1
16 changed files with 217 additions and 13 deletions
@@ -6535,6 +6535,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.kt");
}
@TestMetadata("deprecatedHiddenOnCallableReferenceArgument.kt")
public void testDeprecatedHiddenOnCallableReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHiddenOnCallableReferenceArgument.kt");
}
@TestMetadata("deprecatedInheritance.kt")
public void testDeprecatedInheritance() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.kt");
@@ -6677,6 +6682,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt");
}
@TestMetadata("deprecatedSinceKotlinHiddenOnReferenceArgument.kt")
public void testDeprecatedSinceKotlinHiddenOnReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinHiddenOnReferenceArgument.kt");
}
@TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt")
public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt");
@@ -70,6 +70,18 @@ class KotlinResolutionStatelessCallbacksImpl(
kotlinCall is PSIKotlinCallImpl && kotlinCall.psiCall.isCallWithSuperReceiver(),
)
override fun isHiddenInResolution(
descriptor: DeclarationDescriptor,
kotlinCallArgument: KotlinCallArgument,
resolutionCallbacks: KotlinResolutionCallbacks
): Boolean =
deprecationResolver.isHiddenInResolution(
descriptor,
kotlinCallArgument.psiCallArgument.psiExpression,
(resolutionCallbacks as? KotlinResolutionCallbacksImpl)?.trace?.bindingContext,
isSuperCall = false,
)
override fun isSuperExpression(receiver: SimpleKotlinCallArgument?): Boolean =
receiver?.psiExpression is KtSuperExpression
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.Call
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.SinceKotlinAccessibility
import org.jetbrains.kotlin.resolve.calls.checkers.isOperatorMod
@@ -64,6 +65,14 @@ class DeprecationResolver(
call: Call? = null,
bindingContext: BindingContext? = null,
isSuperCall: Boolean = false
): Boolean =
isHiddenInResolution(descriptor, call?.callElement, bindingContext, isSuperCall)
fun isHiddenInResolution(
descriptor: DeclarationDescriptor,
callElement: KtElement?,
bindingContext: BindingContext?,
isSuperCall: Boolean
): Boolean {
if (descriptor is FunctionDescriptor) {
if (descriptor.isHiddenToOvercomeSignatureClash) return true
@@ -74,10 +83,10 @@ class DeprecationResolver(
if (sinceKotlinAccessibility is SinceKotlinAccessibility.NotAccessible) return true
if (sinceKotlinAccessibility is SinceKotlinAccessibility.NotAccessibleButWasExperimental) {
if (call != null && bindingContext != null) {
if (callElement != null && bindingContext != null) {
return with(ExperimentalUsageChecker) {
sinceKotlinAccessibility.markerClasses.any { classDescriptor ->
!call.callElement.isExperimentalityAccepted(classDescriptor.fqNameSafe, languageVersionSettings, bindingContext)
!callElement.isExperimentalityAccepted(classDescriptor.fqNameSafe, languageVersionSettings, bindingContext)
}
}
}
@@ -186,7 +186,8 @@ class CallableReferencesCandidateFactory(
val scopeTower: ImplicitScopeTower,
val compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit,
val expectedType: UnwrappedType?,
private val csBuilder: ConstraintSystemOperation
private val csBuilder: ConstraintSystemOperation,
private val resolutionCallbacks: KotlinResolutionCallbacks
) : CandidateFactory<CallableReferenceCandidate> {
fun createCallableProcessor(explicitReceiver: DetailedReceiver?) =
@@ -212,6 +213,17 @@ class CallableReferencesCandidateFactory(
callComponents.builtIns
)
fun createReferenceCandidate(): CallableReferenceCandidate =
CallableReferenceCandidate(
candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver,
explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation, diagnostics
)
if (callComponents.statelessCallbacks.isHiddenInResolution(candidateDescriptor, argument, resolutionCallbacks)) {
diagnostics.add(HiddenDescriptor)
return createReferenceCandidate()
}
if (needCompatibilityResolveForCallableReference(callableReferenceAdaptation, candidateDescriptor)) {
markCandidateForCompatibilityResolve(diagnostics)
}
@@ -254,10 +266,7 @@ class CallableReferencesCandidateFactory(
)
}
return CallableReferenceCandidate(
candidateDescriptor, dispatchCallableReceiver, extensionCallableReceiver,
explicitReceiverKind, reflectionCandidateType, callableReferenceAdaptation, diagnostics
)
return createReferenceCandidate()
}
private fun needCompatibilityResolveForCallableReference(
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemOperation
import org.jetbrains.kotlin.resolve.calls.inference.components.ConstraintInjector
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.model.LowerPriorityToPreserveCompatibility
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature
import org.jetbrains.kotlin.resolve.calls.results.OverloadingConflictResolver
@@ -76,13 +75,14 @@ class CallableReferenceResolver(
fun processCallableReferenceArgument(
csBuilder: ConstraintSystemBuilder,
resolvedAtom: ResolvedCallableReferenceAtom,
diagnosticsHolder: KotlinDiagnosticsHolder
diagnosticsHolder: KotlinDiagnosticsHolder,
resolutionCallbacks: KotlinResolutionCallbacks
) {
val argument = resolvedAtom.atom
val expectedType = resolvedAtom.expectedType?.let { (csBuilder.buildCurrentSubstitutor() as NewTypeSubstitutor).safeSubstitute(it) }
val scopeTower = callComponents.statelessCallbacks.getScopeTowerForCallableReferenceArgument(argument)
val candidates = runRHSResolution(scopeTower, argument, expectedType, csBuilder) { checkCallableReference ->
val candidates = runRHSResolution(scopeTower, argument, expectedType, csBuilder, resolutionCallbacks) { checkCallableReference ->
csBuilder.runTransaction { checkCallableReference(this); false }
}
@@ -144,10 +144,11 @@ class CallableReferenceResolver(
callableReference: CallableReferenceKotlinCallArgument,
expectedType: UnwrappedType?, // this type can have not fixed type variable inside
csBuilder: ConstraintSystemBuilder,
resolutionCallbacks: KotlinResolutionCallbacks,
compatibilityChecker: ((ConstraintSystemOperation) -> Unit) -> Unit // you can run anything throw this operation and all this operation will be rolled back
): Set<CallableReferenceCandidate> {
val factory = CallableReferencesCandidateFactory(
callableReference, callComponents, scopeTower, compatibilityChecker, expectedType, csBuilder
callableReference, callComponents, scopeTower, compatibilityChecker, expectedType, csBuilder, resolutionCallbacks
)
val processor = createCallableReferenceProcessor(factory)
val candidates = towerResolver.runResolve(scopeTower, processor, useOrder = true, name = callableReference.rhsName)
@@ -27,6 +27,10 @@ interface KotlinResolutionStatelessCallbacks {
fun isInfixCall(kotlinCall: KotlinCall): Boolean
fun isOperatorCall(kotlinCall: KotlinCall): Boolean
fun isSuperOrDelegatingConstructorCall(kotlinCall: KotlinCall): Boolean
fun isHiddenInResolution(
descriptor: DeclarationDescriptor, kotlinCallArgument: KotlinCallArgument, resolutionCallbacks: KotlinResolutionCallbacks
): Boolean
fun isHiddenInResolution(
descriptor: DeclarationDescriptor, kotlinCall: KotlinCall, resolutionCallbacks: KotlinResolutionCallbacks
): Boolean
@@ -58,7 +58,7 @@ class PostponedArgumentsAnalyzer(
)
is ResolvedCallableReferenceAtom ->
callableReferenceResolver.processCallableReferenceArgument(c.getBuilder(), argument, diagnosticsHolder)
callableReferenceResolver.processCallableReferenceArgument(c.getBuilder(), argument, diagnosticsHolder, resolutionCallbacks)
is ResolvedCollectionLiteralAtom -> TODO("Not supported")
@@ -638,7 +638,7 @@ internal object EagerResolveOfCallableReferences : ResolutionPart() {
getSubResolvedAtoms()
.filterIsInstance<EagerCallableReferenceAtom>()
.forEach {
callableReferenceResolver.processCallableReferenceArgument(csBuilder, it, this)
callableReferenceResolver.processCallableReferenceArgument(csBuilder, it, this, resolutionCallbacks)
}
}
}
@@ -0,0 +1,23 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
object Scope {
fun foo(): Int = 0
object Nested {
@Deprecated("err", level = DeprecationLevel.HIDDEN)
fun foo(): String = ""
fun <T> take(f: () -> T): T = f()
fun test() {
val r1 = take(::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r1<!>
val r2 = ::foo
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction0<kotlin.String>")!>r2<!>
val r3 = foo()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r3<!>
}
}
}
@@ -0,0 +1,23 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
object Scope {
fun foo(): Int = 0
object Nested {
@Deprecated("err", level = DeprecationLevel.HIDDEN)
fun foo(): String = ""
fun <T> take(f: () -> T): T = f()
fun test() {
val r1 = take(::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>r1<!>
val r2 = ::foo
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction0<kotlin.Int>")!>r2<!>
val r3 = foo()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>r3<!>
}
}
}
@@ -0,0 +1,19 @@
package
public object Scope {
private constructor Scope()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public object Nested {
private constructor Nested()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "err") public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun </*0*/ T> take(/*0*/ f: () -> T): T
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
@@ -0,0 +1,26 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
package kotlin
object Scope {
fun foo(): Int = 0
object Nested {
@Deprecated("err")
@DeprecatedSinceKotlin(hiddenSince = "1.0")
fun foo(): String = ""
fun <T> take(f: () -> T): T = f()
fun test() {
val r1 = take(::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r1<!>
val r2 = ::foo
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction0<kotlin.String>")!>r2<!>
val r3 = foo()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>r3<!>
}
}
}
@@ -0,0 +1,26 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION
package kotlin
object Scope {
fun foo(): Int = 0
object Nested {
@Deprecated("err")
@DeprecatedSinceKotlin(hiddenSince = "1.0")
fun foo(): String = ""
fun <T> take(f: () -> T): T = f()
fun test() {
val r1 = take(::foo)
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>r1<!>
val r2 = ::foo
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.reflect.KFunction0<kotlin.Int>")!>r2<!>
val r3 = foo()
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Int")!>r3<!>
}
}
}
@@ -0,0 +1,22 @@
package
package kotlin {
public object Scope {
private constructor Scope()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final fun foo(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public object Nested {
private constructor Nested()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
@kotlin.Deprecated(message = "err") @kotlin.DeprecatedSinceKotlin(hiddenSince = "1.0") public final fun foo(): kotlin.String
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public final fun </*0*/ T> take(/*0*/ f: () -> T): T
public final fun test(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}
@@ -6542,6 +6542,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.kt");
}
@TestMetadata("deprecatedHiddenOnCallableReferenceArgument.kt")
public void testDeprecatedHiddenOnCallableReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHiddenOnCallableReferenceArgument.kt");
}
@TestMetadata("deprecatedInheritance.kt")
public void testDeprecatedInheritance() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.kt");
@@ -6684,6 +6689,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt");
}
@TestMetadata("deprecatedSinceKotlinHiddenOnReferenceArgument.kt")
public void testDeprecatedSinceKotlinHiddenOnReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinHiddenOnReferenceArgument.kt");
}
@TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt")
public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt");
@@ -6537,6 +6537,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHidden.kt");
}
@TestMetadata("deprecatedHiddenOnCallableReferenceArgument.kt")
public void testDeprecatedHiddenOnCallableReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedHiddenOnCallableReferenceArgument.kt");
}
@TestMetadata("deprecatedInheritance.kt")
public void testDeprecatedInheritance() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedInheritance.kt");
@@ -6679,6 +6684,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinDeclaration.kt");
}
@TestMetadata("deprecatedSinceKotlinHiddenOnReferenceArgument.kt")
public void testDeprecatedSinceKotlinHiddenOnReferenceArgument() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinHiddenOnReferenceArgument.kt");
}
@TestMetadata("deprecatedSinceKotlinOutsideKotlinPackage.kt")
public void testDeprecatedSinceKotlinOutsideKotlinPackage() throws Exception {
runTest("compiler/testData/diagnostics/tests/deprecated/deprecatedSinceKotlin/deprecatedSinceKotlinOutsideKotlinPackage.kt");