K2: remove JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE error
This is a partial revert of949a39b80f. In the end it turned out not necessary to prohibit this case (and perform a breaking change), because JVM backend was fixed to generate it correctly ind73d3c46e2. #KT-55307 Declined #KT-55846 Declined
This commit is contained in:
committed by
Space Team
parent
0ccae0d4c6
commit
9ec78e1aa9
-8
@@ -4875,14 +4875,6 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
|||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
add(FirJvmErrors.JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE) { firDiagnostic ->
|
|
||||||
JavaShadowedProtectedFieldReferenceImpl(
|
|
||||||
firDiagnostic.a,
|
|
||||||
firDiagnostic.b,
|
|
||||||
firDiagnostic as KtPsiDiagnostic,
|
|
||||||
token,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
add(FirJsErrors.IMPLEMENTING_FUNCTION_INTERFACE) { firDiagnostic ->
|
add(FirJsErrors.IMPLEMENTING_FUNCTION_INTERFACE) { firDiagnostic ->
|
||||||
ImplementingFunctionInterfaceImpl(
|
ImplementingFunctionInterfaceImpl(
|
||||||
firDiagnostic as KtPsiDiagnostic,
|
firDiagnostic as KtPsiDiagnostic,
|
||||||
|
|||||||
-6
@@ -3395,12 +3395,6 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
|||||||
override val diagnosticClass get() = JavaSamInterfaceConstructorReference::class
|
override val diagnosticClass get() = JavaSamInterfaceConstructorReference::class
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class JavaShadowedProtectedFieldReference : KtFirDiagnostic<PsiElement>() {
|
|
||||||
override val diagnosticClass get() = JavaShadowedProtectedFieldReference::class
|
|
||||||
abstract val containerClass: ClassId
|
|
||||||
abstract val shadowingClass: ClassId
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class ImplementingFunctionInterface : KtFirDiagnostic<KtClassOrObject>() {
|
abstract class ImplementingFunctionInterface : KtFirDiagnostic<KtClassOrObject>() {
|
||||||
override val diagnosticClass get() = ImplementingFunctionInterface::class
|
override val diagnosticClass get() = ImplementingFunctionInterface::class
|
||||||
}
|
}
|
||||||
|
|||||||
-7
@@ -4104,13 +4104,6 @@ internal class JavaSamInterfaceConstructorReferenceImpl(
|
|||||||
override val token: KtLifetimeToken,
|
override val token: KtLifetimeToken,
|
||||||
) : KtFirDiagnostic.JavaSamInterfaceConstructorReference(), KtAbstractFirDiagnostic<PsiElement>
|
) : KtFirDiagnostic.JavaSamInterfaceConstructorReference(), KtAbstractFirDiagnostic<PsiElement>
|
||||||
|
|
||||||
internal class JavaShadowedProtectedFieldReferenceImpl(
|
|
||||||
override val containerClass: ClassId,
|
|
||||||
override val shadowingClass: ClassId,
|
|
||||||
override val firDiagnostic: KtPsiDiagnostic,
|
|
||||||
override val token: KtLifetimeToken,
|
|
||||||
) : KtFirDiagnostic.JavaShadowedProtectedFieldReference(), KtAbstractFirDiagnostic<PsiElement>
|
|
||||||
|
|
||||||
internal class ImplementingFunctionInterfaceImpl(
|
internal class ImplementingFunctionInterfaceImpl(
|
||||||
override val firDiagnostic: KtPsiDiagnostic,
|
override val firDiagnostic: KtPsiDiagnostic,
|
||||||
override val token: KtLifetimeToken,
|
override val token: KtLifetimeToken,
|
||||||
|
|||||||
-4
@@ -188,9 +188,5 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
|
|||||||
PositioningStrategy.SPREAD_OPERATOR
|
PositioningStrategy.SPREAD_OPERATOR
|
||||||
)
|
)
|
||||||
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error<PsiElement>()
|
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error<PsiElement>()
|
||||||
val JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE by error<PsiElement> {
|
|
||||||
parameter<ClassId>("containerClass")
|
|
||||||
parameter<ClassId>("shadowingClass")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
-1
@@ -127,7 +127,6 @@ object FirJvmErrors {
|
|||||||
val CONCURRENT_HASH_MAP_CONTAINS_OPERATOR by deprecationError0<PsiElement>(ProhibitConcurrentHashMapContains)
|
val CONCURRENT_HASH_MAP_CONTAINS_OPERATOR by deprecationError0<PsiElement>(ProhibitConcurrentHashMapContains)
|
||||||
val SPREAD_ON_SIGNATURE_POLYMORPHIC_CALL by deprecationError0<PsiElement>(ProhibitSpreadOnSignaturePolymorphicCall, SourceElementPositioningStrategies.SPREAD_OPERATOR)
|
val SPREAD_ON_SIGNATURE_POLYMORPHIC_CALL by deprecationError0<PsiElement>(ProhibitSpreadOnSignaturePolymorphicCall, SourceElementPositioningStrategies.SPREAD_OPERATOR)
|
||||||
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error0<PsiElement>()
|
val JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE by error0<PsiElement>()
|
||||||
val JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE by error2<PsiElement, ClassId, ClassId>()
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
RootDiagnosticRendererFactory.registerFactory(FirJvmErrorsDefaultMessages)
|
RootDiagnosticRendererFactory.registerFactory(FirJvmErrorsDefaultMessages)
|
||||||
|
|||||||
-9
@@ -32,7 +32,6 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INNER_JVM_
|
|||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_CANT_CALL_DEFAULT_METHOD_VIA_SUPER
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.INTERFACE_STATIC_METHOD_CALL_FROM_JAVA6_TARGET
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_TYPE_MISMATCH
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JAVA_TYPE_MISMATCH
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_DECLARATION
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_DECLARATION
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_JVM6_TARGET
|
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.JVM_DEFAULT_IN_JVM6_TARGET
|
||||||
@@ -282,14 +281,6 @@ object FirJvmErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
|||||||
JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE,
|
JAVA_SAM_INTERFACE_CONSTRUCTOR_REFERENCE,
|
||||||
"Java SAM interface constructor references are prohibited"
|
"Java SAM interface constructor references are prohibited"
|
||||||
)
|
)
|
||||||
map.put(
|
|
||||||
JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE,
|
|
||||||
"It's impossible to refer here a protected Java field from class ''{0}'', " +
|
|
||||||
"because an invisible property from class ''{1}'' shadows it. " +
|
|
||||||
"Rename the property from class ''{1}'' or change visibility of the field from class ''{0}''",
|
|
||||||
TO_STRING,
|
|
||||||
TO_STRING
|
|
||||||
)
|
|
||||||
map.put(
|
map.put(
|
||||||
REDUNDANT_REPEATABLE_ANNOTATION,
|
REDUNDANT_REPEATABLE_ANNOTATION,
|
||||||
"Please, remove the ''{0}'' annotation, as ''{1}'' is already enough",
|
"Please, remove the ''{0}'' annotation, as ''{1}'' is already enough",
|
||||||
|
|||||||
-1
@@ -22,7 +22,6 @@ object JvmExpressionCheckers : ExpressionCheckers() {
|
|||||||
|
|
||||||
override val callableReferenceAccessCheckers: Set<FirCallableReferenceAccessChecker>
|
override val callableReferenceAccessCheckers: Set<FirCallableReferenceAccessChecker>
|
||||||
get() = setOf(
|
get() = setOf(
|
||||||
FirJavaShadowedFieldReferenceChecker,
|
|
||||||
FirUnsupportedSyntheticCallableReferenceChecker,
|
FirUnsupportedSyntheticCallableReferenceChecker,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
-72
@@ -1,72 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
|
||||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.expression
|
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
|
|
||||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
|
||||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirCallableReferenceAccessChecker
|
|
||||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
|
|
||||||
import org.jetbrains.kotlin.fir.containingClassLookupTag
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.hasBackingField
|
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
|
||||||
import org.jetbrains.kotlin.fir.packageFqName
|
|
||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.isSubclassOf
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.scope
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFieldSymbol
|
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
|
||||||
import org.jetbrains.kotlin.fir.types.coneType
|
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
|
||||||
|
|
||||||
object FirJavaShadowedFieldReferenceChecker : FirCallableReferenceAccessChecker() {
|
|
||||||
override fun check(expression: FirCallableReferenceAccess, context: CheckerContext, reporter: DiagnosticReporter) {
|
|
||||||
val reference = expression.calleeReference as? FirResolvedNamedReference ?: return
|
|
||||||
val referredSymbol = reference.resolvedSymbol as? FirFieldSymbol ?: return
|
|
||||||
if (referredSymbol.visibility != JavaVisibilities.ProtectedAndPackage) return
|
|
||||||
val session = context.session
|
|
||||||
val fieldContainingClassSymbol = referredSymbol.containingClassLookupTag()?.toFirRegularClassSymbol(session) ?: return
|
|
||||||
// Would it be visible, if it would be package private instead of protected-and-package?
|
|
||||||
if (context.containingFile?.packageFqName == fieldContainingClassSymbol.classId.packageFqName) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val dispatchReceiver = expression.dispatchReceiver.takeIf { it !is FirNoReceiverExpression } ?: return
|
|
||||||
val scope = dispatchReceiver.typeRef.coneType.scope(
|
|
||||||
session, context.sessionHolder.scopeSession, FakeOverrideTypeCalculator.DoNothing, requiredPhase = FirResolvePhase.TYPES
|
|
||||||
) ?: return
|
|
||||||
|
|
||||||
var shadowingPropertyClassId: ClassId? = null
|
|
||||||
scope.processPropertiesByName(referredSymbol.name) {
|
|
||||||
if (it !is FirPropertySymbol) return@processPropertiesByName
|
|
||||||
if (!it.hasBackingField) return@processPropertiesByName
|
|
||||||
val propertyContainingClassSymbol = it.containingClassLookupTag()?.toFirRegularClassSymbol(session)
|
|
||||||
?: return@processPropertiesByName
|
|
||||||
if (propertyContainingClassSymbol.isSubclassOf(
|
|
||||||
fieldContainingClassSymbol.toLookupTag(), session, isStrict = true, lookupInterfaces = false
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
shadowingPropertyClassId = propertyContainingClassSymbol.classId
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
shadowingPropertyClassId?.let {
|
|
||||||
reporter.reportOn(
|
|
||||||
reference.source,
|
|
||||||
FirJvmErrors.JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE,
|
|
||||||
fieldContainingClassSymbol.classId,
|
|
||||||
it,
|
|
||||||
context
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+3
-3
@@ -52,7 +52,7 @@ open class IntermediatePublic : BaseJava() {
|
|||||||
|
|
||||||
class Derived : Intermediate() {
|
class Derived : Intermediate() {
|
||||||
// This should be the first erroneous place (only in K2)
|
// This should be the first erroneous place (only in K2)
|
||||||
fun foo() = this::<!JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE!>a<!>
|
fun foo() = this::a
|
||||||
|
|
||||||
fun bar() = a // Non-reference
|
fun bar() = a // Non-reference
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ typealias Alias = Intermediate
|
|||||||
|
|
||||||
class DerivedAlias : Alias() {
|
class DerivedAlias : Alias() {
|
||||||
// This should be the second erroneous place (only in K2)
|
// This should be the second erroneous place (only in K2)
|
||||||
fun foo() = this::<!JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE!>a<!>
|
fun foo() = this::a
|
||||||
}
|
}
|
||||||
|
|
||||||
fun local() {
|
fun local() {
|
||||||
@@ -73,7 +73,7 @@ fun local() {
|
|||||||
|
|
||||||
class LocalDerived : LocalIntermediate() {
|
class LocalDerived : LocalIntermediate() {
|
||||||
// This should be the third and the last erroneous place (only in K2)
|
// This should be the third and the last erroneous place (only in K2)
|
||||||
fun foo() = this::<!JAVA_SHADOWED_PROTECTED_FIELD_REFERENCE!>a<!>
|
fun foo() = this::a
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user