[FIR] Add INVISIBLE_SETTER
This commit is contained in:
+2
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
@@ -340,6 +341,7 @@ private object FirToKtConversionCreator {
|
||||
FirModuleData::class,
|
||||
ExpectActualCompatibility.Incompatible::class,
|
||||
DeprecationInfo::class,
|
||||
CallableId::class
|
||||
)
|
||||
|
||||
private val KType.kClass: KClass<*>
|
||||
|
||||
+9
@@ -246,6 +246,15 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.INVISIBLE_SETTER) { firDiagnostic ->
|
||||
InvisibleSetterImpl(
|
||||
firSymbolBuilder.variableLikeBuilder.buildVariableSymbol(firDiagnostic.a.fir),
|
||||
firDiagnostic.b,
|
||||
firDiagnostic.c,
|
||||
firDiagnostic as FirPsiDiagnostic,
|
||||
token,
|
||||
)
|
||||
}
|
||||
add(FirErrors.INVISIBLE_REFERENCE) { firDiagnostic ->
|
||||
InvisibleReferenceImpl(
|
||||
firSymbolBuilder.buildSymbol(firDiagnostic.a.fir),
|
||||
|
||||
+8
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -203,6 +204,13 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
|
||||
abstract val valOrVar: KtKeywordToken
|
||||
}
|
||||
|
||||
abstract class InvisibleSetter : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = InvisibleSetter::class
|
||||
abstract val property: KtVariableSymbol
|
||||
abstract val visibility: Visibility
|
||||
abstract val callableId: CallableId
|
||||
}
|
||||
|
||||
abstract class InvisibleReference : KtFirDiagnostic<PsiElement>() {
|
||||
override val diagnosticClass get() = InvisibleReference::class
|
||||
abstract val reference: KtSymbol
|
||||
|
||||
+9
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirPsiDiagnostic
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -231,6 +232,14 @@ internal class ValOrVarOnSecondaryConstructorParameterImpl(
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.ValOrVarOnSecondaryConstructorParameter(), KtAbstractFirDiagnostic<KtParameter>
|
||||
|
||||
internal class InvisibleSetterImpl(
|
||||
override val property: KtVariableSymbol,
|
||||
override val visibility: Visibility,
|
||||
override val callableId: CallableId,
|
||||
override val firDiagnostic: FirPsiDiagnostic,
|
||||
override val token: ValidityToken,
|
||||
) : KtFirDiagnostic.InvisibleSetter(), KtAbstractFirDiagnostic<PsiElement>
|
||||
|
||||
internal class InvisibleReferenceImpl(
|
||||
override val reference: KtSymbol,
|
||||
override val firDiagnostic: FirPsiDiagnostic,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
RAW_FIR:
|
||||
FILE: annotationParameters.kt
|
||||
public? final? [RAW_FIR] enum class X : R|kotlin/Enum<X>| {
|
||||
@@ -19,7 +20,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [RAW_FIR] class B : R|kotlin/Any| {
|
||||
@@ -56,7 +57,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [RAW_FIR] class B : R|kotlin/Any| {
|
||||
@@ -93,7 +94,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [RAW_FIR] class B : R|kotlin/Any| {
|
||||
@@ -130,7 +131,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -167,7 +168,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -204,7 +205,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -241,7 +242,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -278,7 +279,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [STATUS] class B : R|kotlin/Any| {
|
||||
@@ -315,7 +316,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [SUPER_TYPES] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [STATUS] class B : R|kotlin/Any| {
|
||||
@@ -352,7 +353,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [RAW_FIR] class B : R|kotlin/Any| {
|
||||
@@ -389,7 +390,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [SUPER_TYPES] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [STATUS] class B : R|kotlin/Any| {
|
||||
@@ -426,7 +427,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [SUPER_TYPES] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [STATUS] class B : R|kotlin/Any| {
|
||||
@@ -463,7 +464,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [RAW_FIR] class B : R|kotlin/Any| {
|
||||
@@ -500,7 +501,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -537,7 +538,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -574,7 +575,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -611,7 +612,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public final [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -648,7 +649,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -685,7 +686,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public? final? [RAW_FIR] [IsFromPrimaryConstructor=true] val args: A.X = R|<local>/args|
|
||||
[TYPES] public? get(): A.X
|
||||
[TYPES] [ContainingClassKey=Anno] public? get(): A.X
|
||||
|
||||
}
|
||||
public? final? [SUPER_TYPES] class B : R|kotlin/Any| {
|
||||
@@ -722,7 +723,7 @@ FILE: annotationParameters.kt
|
||||
}
|
||||
|
||||
public final [BODY_RESOLVE] [IsFromPrimaryConstructor=true] val args: <ERROR TYPE REF: Symbol not found for A.X> = R|<local>/args|
|
||||
[BODY_RESOLVE] public get(): <ERROR TYPE REF: Symbol not found for A.X>
|
||||
[BODY_RESOLVE] [ContainingClassKey=Anno] public get(): <ERROR TYPE REF: Symbol not found for A.X>
|
||||
|
||||
}
|
||||
public final [BODY_RESOLVE] class B : R|kotlin/Any| {
|
||||
|
||||
+12
@@ -25481,6 +25481,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("visibleSetterFromSyntheticProperty.kt")
|
||||
public void testVisibleSetterFromSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/visibleSetterFromSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/scopes/classHeader")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -25920,6 +25926,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("protectedPropertyInPrimaryConstructor.kt")
|
||||
public void testProtectedPropertyInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedPropertyInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnExtensionReceiver.kt")
|
||||
public void testSmartcastOnExtensionReceiver() throws Exception {
|
||||
|
||||
+12
@@ -25481,6 +25481,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("visibleSetterFromSyntheticProperty.kt")
|
||||
public void testVisibleSetterFromSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/visibleSetterFromSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/scopes/classHeader")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -25920,6 +25926,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("protectedPropertyInPrimaryConstructor.kt")
|
||||
public void testProtectedPropertyInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedPropertyInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnExtensionReceiver.kt")
|
||||
public void testSmartcastOnExtensionReceiver() throws Exception {
|
||||
|
||||
+12
@@ -25481,6 +25481,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("visibleSetterFromSyntheticProperty.kt")
|
||||
public void testVisibleSetterFromSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/visibleSetterFromSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/scopes/classHeader")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -25920,6 +25926,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("protectedPropertyInPrimaryConstructor.kt")
|
||||
public void testProtectedPropertyInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedPropertyInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnExtensionReceiver.kt")
|
||||
public void testSmartcastOnExtensionReceiver() throws Exception {
|
||||
|
||||
+6
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
@@ -88,6 +89,11 @@ object DIAGNOSTICS_LIST : DiagnosticList("FirErrors") {
|
||||
val VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER by warning<KtParameter>(PositioningStrategy.VAL_OR_VAR_NODE) {
|
||||
parameter<KtKeywordToken>("valOrVar")
|
||||
}
|
||||
val INVISIBLE_SETTER by error<PsiElement>(PositioningStrategy.ASSIGNMENT_LHS) {
|
||||
parameter<FirPropertySymbol>("property")
|
||||
parameter<Visibility>("visibility")
|
||||
parameter<CallableId>("callableId")
|
||||
}
|
||||
}
|
||||
|
||||
val UNRESOLVED by object : DiagnosticGroup("Unresolved") {
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.lexer.KtKeywordToken
|
||||
import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtAnnotationEntry
|
||||
@@ -128,6 +129,7 @@ object FirErrors {
|
||||
val VAL_OR_VAR_ON_FUN_PARAMETER by warning1<KtParameter, KtKeywordToken>(SourceElementPositioningStrategies.VAL_OR_VAR_NODE)
|
||||
val VAL_OR_VAR_ON_CATCH_PARAMETER by warning1<KtParameter, KtKeywordToken>(SourceElementPositioningStrategies.VAL_OR_VAR_NODE)
|
||||
val VAL_OR_VAR_ON_SECONDARY_CONSTRUCTOR_PARAMETER by warning1<KtParameter, KtKeywordToken>(SourceElementPositioningStrategies.VAL_OR_VAR_NODE)
|
||||
val INVISIBLE_SETTER by error3<PsiElement, FirPropertySymbol, Visibility, CallableId>(SourceElementPositioningStrategies.ASSIGNMENT_LHS)
|
||||
|
||||
// Unresolved
|
||||
val INVISIBLE_REFERENCE by error1<PsiElement, FirBasedSymbol<*>>(SourceElementPositioningStrategies.REFERENCE_BY_QUALIFIED)
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ object CommonExpressionCheckers : ExpressionCheckers() {
|
||||
|
||||
override val variableAssignmentCheckers: Set<FirVariableAssignmentChecker>
|
||||
get() = setOf(
|
||||
FirValReassignmentChecker,
|
||||
FirReassignmentAndInvisibleSetterChecker,
|
||||
FirAssignmentTypeMismatchChecker
|
||||
)
|
||||
|
||||
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.toRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.expressions.FirExpressionWithSmartcast
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
|
||||
import org.jetbrains.kotlin.fir.expressions.toResolvedCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.originalForSubstitutionOverride
|
||||
import org.jetbrains.kotlin.fir.references.FirBackingFieldReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ExpressionReceiverValue
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.visibilityChecker
|
||||
|
||||
object FirReassignmentAndInvisibleSetterChecker : FirVariableAssignmentChecker() {
|
||||
override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
checkInvisibleSetter(expression, context, reporter)
|
||||
checkValReassignmentViaBackingField(expression, context, reporter)
|
||||
checkValReassignmentOnValueParameter(expression, context, reporter)
|
||||
}
|
||||
|
||||
private fun checkInvisibleSetter(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
fun shouldInvisibleSetterBeReported(symbol: FirPropertySymbol): Boolean {
|
||||
@OptIn(SymbolInternals::class)
|
||||
val setterFir = symbol.setterSymbol?.fir ?: symbol.originalForSubstitutionOverride?.setterSymbol?.fir
|
||||
if (setterFir != null) {
|
||||
return !context.session.visibilityChecker.isVisible(
|
||||
setterFir,
|
||||
context.session,
|
||||
context.findClosest()!!,
|
||||
context.containingDeclarations,
|
||||
ExpressionReceiverValue(expression.dispatchReceiver),
|
||||
)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
val callableSymbol = expression.calleeReference.toResolvedCallableSymbol()
|
||||
if (callableSymbol is FirPropertySymbol && shouldInvisibleSetterBeReported(callableSymbol)) {
|
||||
val explicitReceiver = expression.explicitReceiver
|
||||
// Try to get type from smartcast
|
||||
if (explicitReceiver is FirExpressionWithSmartcast) {
|
||||
val symbol = explicitReceiver.originalType.toRegularClassSymbol(context.session)
|
||||
if (symbol != null) {
|
||||
for (declarationSymbol in symbol.declarationSymbols) {
|
||||
if (declarationSymbol is FirPropertySymbol && declarationSymbol.name == callableSymbol.name) {
|
||||
if (!shouldInvisibleSetterBeReported(declarationSymbol)) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
reporter.reportOn(
|
||||
expression.source,
|
||||
FirErrors.INVISIBLE_SETTER,
|
||||
callableSymbol,
|
||||
callableSymbol.setterSymbol?.visibility ?: Visibilities.Private,
|
||||
callableSymbol.callableId,
|
||||
context
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkValReassignmentViaBackingField(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
val backingFieldReference = expression.lValue as? FirBackingFieldReference ?: return
|
||||
val propertySymbol = backingFieldReference.resolvedSymbol
|
||||
if (propertySymbol.isVar) return
|
||||
val closestGetter = context.findClosest<FirPropertyAccessor> { it.isGetter }?.symbol ?: return
|
||||
if (propertySymbol.getterSymbol != closestGetter) return
|
||||
|
||||
reporter.reportOn(backingFieldReference.source, FirErrors.VAL_REASSIGNMENT_VIA_BACKING_FIELD, propertySymbol, context)
|
||||
}
|
||||
|
||||
private fun checkValReassignmentOnValueParameter(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
val valueParameter = (expression.lValue as? FirResolvedNamedReference)?.resolvedSymbol as? FirValueParameterSymbol ?: return
|
||||
reporter.reportOn(expression.lValue.source, FirErrors.VAL_REASSIGNMENT, valueParameter, context)
|
||||
}
|
||||
}
|
||||
-49
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2021 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.checkers.expression
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.findClosest
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
|
||||
import org.jetbrains.kotlin.fir.languageVersionSettings
|
||||
import org.jetbrains.kotlin.fir.references.FirBackingFieldReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirValueParameterSymbol
|
||||
|
||||
object FirValReassignmentChecker : FirVariableAssignmentChecker() {
|
||||
override fun check(expression: FirVariableAssignment, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
checkValReassignmentViaBackingField(expression, context, reporter)
|
||||
checkValReassignmentOnValueParameter(expression, context, reporter)
|
||||
}
|
||||
|
||||
private fun checkValReassignmentViaBackingField(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
val backingFieldReference = expression.lValue as? FirBackingFieldReference ?: return
|
||||
val propertySymbol = backingFieldReference.resolvedSymbol
|
||||
if (propertySymbol.isVar) return
|
||||
val closestGetter = context.findClosest<FirPropertyAccessor> { it.isGetter }?.symbol ?: return
|
||||
if (propertySymbol.getterSymbol != closestGetter) return
|
||||
|
||||
reporter.reportOn(backingFieldReference.source, FirErrors.VAL_REASSIGNMENT_VIA_BACKING_FIELD, propertySymbol, context)
|
||||
}
|
||||
|
||||
private fun checkValReassignmentOnValueParameter(
|
||||
expression: FirVariableAssignment,
|
||||
context: CheckerContext,
|
||||
reporter: DiagnosticReporter
|
||||
) {
|
||||
val valueParameter = (expression.lValue as? FirResolvedNamedReference)?.resolvedSymbol as? FirValueParameterSymbol ?: return
|
||||
reporter.reportOn(expression.lValue.source, FirErrors.VAL_REASSIGNMENT, valueParameter, context)
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FIR
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FQ_NAMES_IN_TYPES
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.FUNCTION_PARAMETERS
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.MODULE_DATA
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.NAME_OF_CONTAINING_DECLARATION_OR_FILE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.NOT_RENDERED
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.NULLABLE_STRING
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticRenderers.RENDER_CLASS_OR_OBJECT
|
||||
@@ -247,6 +248,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVALID_DEFAULT_F
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVALID_IF_AS_EXPRESSION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVISIBLE_REFERENCE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVISIBLE_SETTER
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.IS_ENUM_ENTRY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.ITERATOR_AMBIGUITY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.KCLASS_WITH_NULLABLE_TYPE_PARAMETER_IN_SIGNATURE
|
||||
@@ -554,6 +556,7 @@ class FirDefaultErrorMessages {
|
||||
|
||||
// Unresolved
|
||||
map.put(INVISIBLE_REFERENCE, "Symbol {0} is invisible", SYMBOL)
|
||||
map.put(INVISIBLE_SETTER, "Cannot access ''{0}'': it is {1} in {2}", VARIABLE_NAME, VISIBILITY, NAME_OF_CONTAINING_DECLARATION_OR_FILE)
|
||||
map.put(UNRESOLVED_REFERENCE, "Unresolved reference: {0}", NULLABLE_STRING)
|
||||
map.put(UNRESOLVED_LABEL, "Unresolved label")
|
||||
map.put(DESERIALIZATION_ERROR, "Deserialization error")
|
||||
|
||||
+10
-3
@@ -14,16 +14,14 @@ import org.jetbrains.kotlin.diagnostics.rendering.Renderer
|
||||
import org.jetbrains.kotlin.fir.FirElement
|
||||
import org.jetbrains.kotlin.fir.FirModuleData
|
||||
import org.jetbrains.kotlin.fir.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.isLocalClassOrAnonymousObject
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.firUnsafe
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.SymbolInternals
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.render
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
|
||||
object FirDiagnosticRenderers {
|
||||
val NULLABLE_STRING = Renderer<String?> { it ?: "null" }
|
||||
@@ -139,6 +137,15 @@ object FirDiagnosticRenderers {
|
||||
"Module ${it.name}"
|
||||
}
|
||||
|
||||
val NAME_OF_CONTAINING_DECLARATION_OR_FILE = Renderer { symbol: CallableId ->
|
||||
val classId = symbol.classId
|
||||
if (classId == null) {
|
||||
"file"
|
||||
} else {
|
||||
"'${classId}'"
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun <T> COLLECTION(renderer: ContextIndependentParameterRenderer<T>): ContextIndependentParameterRenderer<Collection<T>> {
|
||||
return Renderer { list ->
|
||||
|
||||
@@ -11,11 +11,13 @@ import org.jetbrains.kotlin.descriptors.java.JavaVisibilities
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFile
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertySymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ReceiverValue
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirPropertyAccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||
|
||||
@NoMutableState
|
||||
@@ -37,19 +39,25 @@ object FirJavaVisibilityChecker : FirVisibilityChecker() {
|
||||
val ownerLookupTag = symbol.getOwnerLookupTag() ?: return false
|
||||
if (canSeeProtectedMemberOf(
|
||||
containingDeclarations, dispatchReceiver, ownerLookupTag, session,
|
||||
isVariableOrNamedFunction = symbol is FirVariableSymbol || symbol is FirNamedFunctionSymbol
|
||||
isVariableOrNamedFunction = symbol is FirVariableSymbol || symbol is FirNamedFunctionSymbol || symbol is FirPropertyAccessorSymbol,
|
||||
isSyntheticProperty = symbol.fir is FirSyntheticPropertyAccessor
|
||||
)
|
||||
) return true
|
||||
|
||||
// FE1.0 allows calling public setters with property assignment syntax if the getter is protected.
|
||||
if (!isCallToPropertySetter || symbol !is FirSyntheticPropertySymbol) return false
|
||||
val setterVisibility = symbol.setterSymbol?.visibility
|
||||
setterVisibility != null && setterVisibility == Visibilities.Public
|
||||
symbol.setterSymbol?.visibility == Visibilities.Public
|
||||
}
|
||||
}
|
||||
|
||||
JavaVisibilities.PackageVisibility -> {
|
||||
symbol.packageFqName() == useSiteFile.packageFqName
|
||||
if (symbol.packageFqName() == useSiteFile.packageFqName) {
|
||||
true
|
||||
} else if (symbol.fir is FirSyntheticPropertyAccessor) {
|
||||
symbol.getOwnerLookupTag()?.classId?.packageFqName == useSiteFile.packageFqName
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
else -> true
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ FILE: annotation.kt
|
||||
}
|
||||
|
||||
@base() public? final? [IsFromPrimaryConstructor=true] val x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=correct] public? get(): Int
|
||||
|
||||
@base() public? [ContainingClassKey=correct] constructor(): R|correct| {
|
||||
this<R|correct|>(IntegerLiteral(0))
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ FILE: derivedClass.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val x: T = R|<local>/x|
|
||||
public? get(): T
|
||||
[ContainingClassKey=Base] public? get(): T
|
||||
|
||||
}
|
||||
public? final? class Derived<T : Any> : Base<T> {
|
||||
|
||||
@@ -20,10 +20,10 @@ FILE: enums.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val m: Double = R|<local>/m|
|
||||
public? get(): Double
|
||||
[ContainingClassKey=Planet] public? get(): Double
|
||||
|
||||
internal final? [IsFromPrimaryConstructor=true] val r: Double = R|<local>/r|
|
||||
internal get(): Double
|
||||
[ContainingClassKey=Planet] internal get(): Double
|
||||
|
||||
public final static [ContainingClassKey=Planet] enum entry MERCURY: R|Planet| = object : R|Planet| {
|
||||
private [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
|
||||
@@ -86,7 +86,7 @@ FILE: enums.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val signature: String = R|<local>/signature|
|
||||
public? get(): String
|
||||
[ContainingClassKey=PseudoInsn] public? get(): String
|
||||
|
||||
public final static [ContainingClassKey=PseudoInsn] enum entry FIX_STACK_BEFORE_JUMP: R|PseudoInsn| = object : R|PseudoInsn| {
|
||||
private [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
|
||||
|
||||
@@ -19,7 +19,7 @@ FILE: enums2.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val x: Some = R|<local>/x|
|
||||
public? get(): Some
|
||||
[ContainingClassKey=SomeEnum] public? get(): Some
|
||||
|
||||
public final static [ContainingClassKey=SomeEnum] enum entry FIRST: R|SomeEnum| = object : R|SomeEnum| {
|
||||
private [ContainingClassKey=<anonymous>] constructor(): R|<anonymous>| {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ FILE: nestedClass.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val s: String = R|<local>/s|
|
||||
public? get(): String
|
||||
[ContainingClassKey=Base] public? get(): String
|
||||
|
||||
}
|
||||
public? final? class Outer : R|kotlin/Any| {
|
||||
|
||||
@@ -26,10 +26,10 @@ FILE: annotated.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Two] public? get(): Int
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val y: Int = R|<local>/y|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Two] public? get(): Int
|
||||
|
||||
public final operator fun component1(): Int
|
||||
|
||||
|
||||
+1
-1
@@ -10,7 +10,7 @@ FILE: arrayAccess.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val v: IntArray = R|<local>/v|
|
||||
public? get(): IntArray
|
||||
[ContainingClassKey=Wrapper] public? get(): IntArray
|
||||
|
||||
}
|
||||
public? final? fun test(a: IntArray, w: Wrapper): <implicit> {
|
||||
|
||||
@@ -14,8 +14,8 @@ FILE: calls.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] var x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
public? set(value: Int): R|kotlin/Unit|
|
||||
[ContainingClassKey=My] public? get(): Int
|
||||
[ContainingClassKey=My] public? set(value: Int): R|kotlin/Unit|
|
||||
|
||||
public? final? operator fun invoke(): <implicit> {
|
||||
^invoke x#
|
||||
|
||||
+3
-3
@@ -5,7 +5,7 @@ FILE: collectionLiterals.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val arr: IntArray = R|<local>/arr|
|
||||
public? get(): IntArray
|
||||
[ContainingClassKey=Ann1] public? get(): IntArray
|
||||
|
||||
}
|
||||
public? final? annotation class Ann2 : R|kotlin/Annotation| {
|
||||
@@ -14,7 +14,7 @@ FILE: collectionLiterals.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val arr: DoubleArray = R|<local>/arr|
|
||||
public? get(): DoubleArray
|
||||
[ContainingClassKey=Ann2] public? get(): DoubleArray
|
||||
|
||||
}
|
||||
public? final? annotation class Ann3 : R|kotlin/Annotation| {
|
||||
@@ -23,7 +23,7 @@ FILE: collectionLiterals.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val arr: Array<String> = R|<local>/arr|
|
||||
public? get(): Array<String>
|
||||
[ContainingClassKey=Ann3] public? get(): Array<String>
|
||||
|
||||
}
|
||||
@Ann1(<implicitArrayOf>()) @Ann2(<implicitArrayOf>()) @Ann3(<implicitArrayOf>()) public? final? class Zero : R|kotlin/Any| {
|
||||
|
||||
+3
-3
@@ -5,13 +5,13 @@ FILE: destructuring.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val first: Int = R|<local>/first|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Some] public? get(): Int
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val second: Double = R|<local>/second|
|
||||
public? get(): Double
|
||||
[ContainingClassKey=Some] public? get(): Double
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val third: String = R|<local>/third|
|
||||
public? get(): String
|
||||
[ContainingClassKey=Some] public? get(): String
|
||||
|
||||
public final operator fun component1(): Int
|
||||
|
||||
|
||||
@@ -55,10 +55,10 @@ FILE: for.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Some] public? get(): Int
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val y: Int = R|<local>/y|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Some] public? get(): Int
|
||||
|
||||
public final operator fun component1(): Int
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@ FILE: lambda.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val x: Int = R|<local>/x|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Tuple] public? get(): Int
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val y: Int = R|<local>/y|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Tuple] public? get(): Int
|
||||
|
||||
public final operator fun component1(): Int
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ FILE: locals.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val pp: Int = R|<local>/pp|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=Local] public? get(): Int
|
||||
|
||||
public? final? fun diff(): <implicit> {
|
||||
^diff pp#.minus#(p#)
|
||||
|
||||
@@ -36,7 +36,7 @@ FILE: unary.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val i: Int = R|<local>/i|
|
||||
public? get(): Int
|
||||
[ContainingClassKey=X] public? get(): Int
|
||||
|
||||
}
|
||||
public? final? fun test2(x: X): R|kotlin/Unit| {
|
||||
@@ -79,7 +79,7 @@ FILE: unary.kt
|
||||
}
|
||||
|
||||
public? final? [IsFromPrimaryConstructor=true] val arr: Array<Int> = R|<local>/arr|
|
||||
public? get(): Array<Int>
|
||||
[ContainingClassKey=Y] public? get(): Array<Int>
|
||||
|
||||
}
|
||||
public? final? fun test4(y: Y): R|kotlin/Unit| {
|
||||
|
||||
@@ -5,18 +5,17 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirPropertyAccessExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirVariableAssignment
|
||||
import org.jetbrains.kotlin.fir.references.FirSuperReference
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ExpressionReceiverValue
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.ReceiverValue
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.*
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
@@ -167,7 +166,8 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
val ownerId = symbol.getOwnerLookupTag()
|
||||
ownerId != null && canSeeProtectedMemberOf(
|
||||
containingDeclarations, dispatchReceiver, ownerId, session,
|
||||
isVariableOrNamedFunction = symbol is FirVariableSymbol || symbol is FirNamedFunctionSymbol
|
||||
isVariableOrNamedFunction = symbol is FirVariableSymbol || symbol is FirNamedFunctionSymbol || symbol is FirPropertyAccessorSymbol,
|
||||
symbol.fir is FirSyntheticPropertyAccessor
|
||||
)
|
||||
}
|
||||
|
||||
@@ -233,7 +233,8 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
dispatchReceiver: ReceiverValue?,
|
||||
ownerLookupTag: ConeClassLikeLookupTag,
|
||||
session: FirSession,
|
||||
isVariableOrNamedFunction: Boolean
|
||||
isVariableOrNamedFunction: Boolean,
|
||||
isSyntheticProperty: Boolean
|
||||
): Boolean {
|
||||
dispatchReceiver?.ownerIfCompanion(session)?.let { companionOwnerLookupTag ->
|
||||
if (containingUseSiteClass.isSubClass(companionOwnerLookupTag, session)) return true
|
||||
@@ -241,7 +242,13 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
|
||||
return when {
|
||||
!containingUseSiteClass.isSubClass(ownerLookupTag, session) -> false
|
||||
isVariableOrNamedFunction -> doesReceiverFitForProtectedVisibility(dispatchReceiver, containingUseSiteClass, session)
|
||||
isVariableOrNamedFunction -> doesReceiverFitForProtectedVisibility(
|
||||
dispatchReceiver,
|
||||
containingUseSiteClass,
|
||||
ownerLookupTag,
|
||||
isSyntheticProperty,
|
||||
session
|
||||
)
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
@@ -249,6 +256,8 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
private fun doesReceiverFitForProtectedVisibility(
|
||||
dispatchReceiver: ReceiverValue?,
|
||||
containingUseSiteClass: FirClass,
|
||||
ownerLookupTag: ConeClassLikeLookupTag,
|
||||
isSyntheticProperty: Boolean,
|
||||
session: FirSession
|
||||
): Boolean {
|
||||
if (dispatchReceiver == null) return true
|
||||
@@ -264,9 +273,21 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = false
|
||||
)
|
||||
return AbstractTypeChecker.isSubtypeOf(
|
||||
typeCheckerState, dispatchReceiverType.fullyExpandedType(session), containingUseSiteClass.typeWithStarProjections()
|
||||
)
|
||||
if (AbstractTypeChecker.isSubtypeOf(
|
||||
typeCheckerState, dispatchReceiverType.fullyExpandedType(session), containingUseSiteClass.typeWithStarProjections()
|
||||
)
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (isSyntheticProperty) {
|
||||
return if (session.languageVersionSettings.supportsFeature(LanguageFeature.ImproveReportingDiagnosticsOnProtectedMembersOfBaseClass))
|
||||
containingUseSiteClass.classId.packageFqName == ownerLookupTag.classId.packageFqName
|
||||
else
|
||||
true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun FirClass.isSubClass(ownerLookupTag: ConeClassLikeLookupTag, session: FirSession): Boolean {
|
||||
@@ -295,14 +316,31 @@ abstract class FirVisibilityChecker : FirSessionComponent {
|
||||
dispatchReceiver: ReceiverValue?,
|
||||
ownerLookupTag: ConeClassLikeLookupTag,
|
||||
session: FirSession,
|
||||
isVariableOrNamedFunction: Boolean
|
||||
isVariableOrNamedFunction: Boolean,
|
||||
isSyntheticProperty: Boolean
|
||||
): Boolean {
|
||||
if (canSeePrivateMemberOf(containingDeclarationOfUseSite, ownerLookupTag, session)) return true
|
||||
|
||||
for (containingDeclaration in containingDeclarationOfUseSite) {
|
||||
if (containingDeclaration !is FirClass) continue
|
||||
val boundSymbol = containingDeclaration.symbol
|
||||
if (canSeeProtectedMemberOf(boundSymbol.fir, dispatchReceiver, ownerLookupTag, session, isVariableOrNamedFunction)) return true
|
||||
if (containingDeclaration is FirClass) {
|
||||
val boundSymbol = containingDeclaration.symbol
|
||||
if (canSeeProtectedMemberOf(
|
||||
boundSymbol.fir,
|
||||
dispatchReceiver,
|
||||
ownerLookupTag,
|
||||
session,
|
||||
isVariableOrNamedFunction,
|
||||
isSyntheticProperty
|
||||
)
|
||||
) return true
|
||||
} else if (containingDeclaration is FirFile) {
|
||||
if (isSyntheticProperty &&
|
||||
session.languageVersionSettings.supportsFeature(LanguageFeature.ImproveReportingDiagnosticsOnProtectedMembersOfBaseClass) &&
|
||||
containingDeclaration.packageFqName == ownerLookupTag.classId.packageFqName
|
||||
) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
public interface ITest {
|
||||
public var prop : Int
|
||||
get() = 12
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
abstract class ATest {
|
||||
protected open var prop2 : Int
|
||||
get() = 13
|
||||
set(value) {}
|
||||
}
|
||||
|
||||
class Test: ATest(), ITest {
|
||||
override var prop : Int
|
||||
get() = 12
|
||||
<!CANNOT_WEAKEN_ACCESS_PRIVILEGE!>private<!> set(value) {}
|
||||
|
||||
override var prop2 : Int
|
||||
get() = 14
|
||||
<!CANNOT_CHANGE_ACCESS_PRIVILEGE, SETTER_VISIBILITY_INCONSISTENT_WITH_PROPERTY_VISIBILITY!>internal<!> set(value) {}
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val test = Test()
|
||||
test.prop = 12
|
||||
|
||||
val itest: ITest = test
|
||||
itest.prop = 12 // No error here
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
public interface ITest {
|
||||
public var prop : Int
|
||||
get() = 12
|
||||
|
||||
@@ -23,23 +23,23 @@ class P {
|
||||
|
||||
fun foo() {
|
||||
val p = P()
|
||||
p.x = 34 //should be an error here
|
||||
<!INVISIBLE_SETTER!>p.x<!> = 34 //should be an error here
|
||||
p.y = 23
|
||||
|
||||
fun inner() {
|
||||
p.x = 44
|
||||
<!INVISIBLE_SETTER!>p.x<!> = 44
|
||||
}
|
||||
}
|
||||
|
||||
class R {
|
||||
val p = P();
|
||||
init {
|
||||
p.x = 42
|
||||
<!INVISIBLE_SETTER!>p.x<!> = 42
|
||||
}
|
||||
|
||||
val testInGetterInOtherClass : Int
|
||||
get() {
|
||||
p.x = 33
|
||||
<!INVISIBLE_SETTER!>p.x<!> = 33
|
||||
return 3
|
||||
}
|
||||
}
|
||||
@@ -50,4 +50,4 @@ fun test() {
|
||||
<!UNRESOLVED_REFERENCE!>p<!>.x = 43
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
//KT-2960 Perform control flow checks for package property initializers
|
||||
|
||||
package b
|
||||
|
||||
class P {
|
||||
var x : Int = 0
|
||||
private set
|
||||
}
|
||||
|
||||
val p = P()
|
||||
var f = { -> p.x = 32 }
|
||||
|
||||
val o = object {
|
||||
fun run() {
|
||||
p.x = 4
|
||||
|
||||
val z : Int
|
||||
doSmth(<!UNINITIALIZED_VARIABLE!>z<!>)
|
||||
}
|
||||
}
|
||||
|
||||
val g = { ->
|
||||
val x: Int
|
||||
doSmth(<!UNINITIALIZED_VARIABLE!>x<!>)
|
||||
}
|
||||
|
||||
class A {
|
||||
val a : Int = 1
|
||||
get() {
|
||||
val x : Int
|
||||
doSmth(<!UNINITIALIZED_VARIABLE!>x<!>)
|
||||
return field
|
||||
}
|
||||
}
|
||||
|
||||
fun doSmth(i: Int) = i
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
//KT-2960 Perform control flow checks for package property initializers
|
||||
|
||||
package b
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
open class X(s : String) {
|
||||
public var n: String = s
|
||||
private set
|
||||
|
||||
}
|
||||
|
||||
class Z : X("subclass") {
|
||||
fun print(): String {
|
||||
n = n
|
||||
return n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun box() : String {
|
||||
return Z().print() //error
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
open class X(s : String) {
|
||||
public var n: String = s
|
||||
private set
|
||||
|
||||
@@ -40,7 +40,7 @@ fun test() {
|
||||
val po = <!INVISIBLE_REFERENCE!>PO<!>
|
||||
|
||||
val v = xx
|
||||
xx = 40
|
||||
<!INVISIBLE_SETTER("xx; private; file")!>xx<!> = 40
|
||||
}
|
||||
|
||||
class B : <!EXPOSED_SUPER_CLASS, INVISIBLE_REFERENCE!>A<!>() {}
|
||||
|
||||
+2
-2
@@ -28,14 +28,14 @@ fun test(s: bar.Sub<String>) {
|
||||
s.<!INVISIBLE_REFERENCE!>name<!>
|
||||
s.<!INVISIBLE_REFERENCE!>name<!> = ""
|
||||
s.name2
|
||||
s.name2 = ""
|
||||
<!INVISIBLE_SETTER!>s.name2<!> = ""
|
||||
s.<!INVISIBLE_REFERENCE!>doSomething<!>()
|
||||
s.doSomething2()
|
||||
val s2: Super<String> = s
|
||||
s2.<!INVISIBLE_REFERENCE!>name<!>
|
||||
s2.<!INVISIBLE_REFERENCE!>name<!> = ""
|
||||
s2.name2
|
||||
s2.name2 = ""
|
||||
<!INVISIBLE_SETTER!>s2.name2<!> = ""
|
||||
s2.<!INVISIBLE_REFERENCE!>doSomething<!>()
|
||||
s2.doSomething2()
|
||||
}
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
class A<T> {
|
||||
public var x: Int = 0
|
||||
private set
|
||||
}
|
||||
|
||||
fun main() {
|
||||
val a = A<Any>()
|
||||
a.x = 1
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
class A<T> {
|
||||
public var x: Int = 0
|
||||
private set
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// FIR_IDENTICAL
|
||||
class Test(protected var prop1: Int = 1) {
|
||||
protected var prop2: Int = 2
|
||||
|
||||
private fun test() {
|
||||
prop1 = 3
|
||||
prop2 = 4
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package
|
||||
|
||||
public final class Test {
|
||||
public constructor Test(/*0*/ prop1: kotlin.Int = ...)
|
||||
protected final var prop1: kotlin.Int
|
||||
protected final var prop2: kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
private final fun test(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Vendored
+3
-5
@@ -22,8 +22,7 @@ class B : A() {
|
||||
b.bar = b.bar + ""
|
||||
|
||||
a.<!INVISIBLE_REFERENCE!>foo<!>
|
||||
// TODO: should be INVISIBLE_SETTER
|
||||
a.bar = a.bar + ""
|
||||
<!INVISIBLE_SETTER!>a.bar<!> = a.bar + ""
|
||||
|
||||
if (a is B) {
|
||||
a.foo
|
||||
@@ -33,13 +32,12 @@ class B : A() {
|
||||
if (d.x is B) {
|
||||
d.x.abc // Ok
|
||||
d.x.<!INVISIBLE_REFERENCE!>foo<!>
|
||||
// TODO: should be INVISIBLE_SETTER
|
||||
d.x.bar = d.x.bar + ""
|
||||
<!INVISIBLE_SETTER!>d.x.bar<!> = d.x.bar + ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun baz(a: A) {
|
||||
a.<!INVISIBLE_REFERENCE!>foo<!>
|
||||
a.bar = a.bar + ""
|
||||
<!INVISIBLE_SETTER!>a.bar<!> = a.bar + ""
|
||||
}
|
||||
|
||||
Vendored
-2
@@ -22,7 +22,6 @@ class B : A() {
|
||||
b.bar = b.bar + ""
|
||||
|
||||
a.<!INVISIBLE_MEMBER!>foo<!>
|
||||
// TODO: should be INVISIBLE_SETTER
|
||||
a.<!INVISIBLE_SETTER!>bar<!> = a.bar + ""
|
||||
|
||||
if (a is B) {
|
||||
@@ -33,7 +32,6 @@ class B : A() {
|
||||
if (d.x is B) {
|
||||
d.x.abc // Ok
|
||||
d.x.<!INVISIBLE_MEMBER!>foo<!>
|
||||
// TODO: should be INVISIBLE_SETTER
|
||||
d.x.<!INVISIBLE_SETTER!>bar<!> = d.x.bar + ""
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ class Derived : Base() {
|
||||
x.<!INVISIBLE_REFERENCE!>bar<!>()
|
||||
|
||||
x.<!INVISIBLE_REFERENCE!>x<!> = x.<!INVISIBLE_REFERENCE!>x<!> + 1
|
||||
x.y = x.y + 1
|
||||
<!INVISIBLE_SETTER!>x.y<!> = x.y + 1
|
||||
|
||||
if (x is Derived) {
|
||||
x.foo()
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// FIR_IDENTICAL
|
||||
|
||||
// FILE: Java.java
|
||||
|
||||
public abstract class Java {
|
||||
private String _name = null;
|
||||
|
||||
void setName(String name) {
|
||||
this._name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return _name;
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun Java.test(name: String) {
|
||||
this.name = name
|
||||
}
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public fun Java.test(/*0*/ name: kotlin.String): kotlin.Unit
|
||||
|
||||
public abstract class Java {
|
||||
public constructor Java()
|
||||
private final var _name: kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open fun getName(): kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public/*package*/ open fun setName(/*0*/ name: kotlin.String!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
+1
-1
@@ -8,7 +8,7 @@ fun foo(javaClass: JavaClass) {
|
||||
javaClass.<!INVISIBLE_REFERENCE!>somethingProtected<!>
|
||||
javaClass.<!INVISIBLE_REFERENCE!>somethingPrivate<!>
|
||||
javaClass.<!INVISIBLE_REFERENCE!>somethingPackage<!>
|
||||
javaClass.somethingPublic = 1
|
||||
<!INVISIBLE_SETTER!>javaClass.somethingPublic<!> = 1
|
||||
}
|
||||
|
||||
// FILE: JavaClass.java
|
||||
|
||||
+4
-4
@@ -18,12 +18,12 @@ class Data(var x: Foo)
|
||||
|
||||
class B : Foo() {
|
||||
fun baz(a: Foo, t: Foo, d: Data) {
|
||||
a.bar = t.bar
|
||||
a.foo = t.foo
|
||||
<!INVISIBLE_SETTER!>a.bar<!> = t.bar
|
||||
<!INVISIBLE_SETTER!>a.foo<!> = t.foo
|
||||
|
||||
if (d.x is B) {
|
||||
d.x.bar = d.x.bar + ""
|
||||
d.x.foo = d.x.foo + ""
|
||||
<!INVISIBLE_SETTER!>d.x.bar<!> = d.x.bar + ""
|
||||
<!INVISIBLE_SETTER!>d.x.foo<!> = d.x.foo + ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -19,11 +19,11 @@ class Data(var x: Foo)
|
||||
class B : Foo() {
|
||||
fun baz(a: Foo, t: Foo, d: Data) {
|
||||
a.bar = t.bar
|
||||
a.foo = t.foo
|
||||
<!INVISIBLE_SETTER!>a.foo<!> = t.foo
|
||||
|
||||
if (d.x is B) {
|
||||
d.x.bar = d.x.bar + ""
|
||||
d.x.foo = d.x.foo + ""
|
||||
<!INVISIBLE_SETTER!>d.x.foo<!> = d.x.foo + ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+2
-2
@@ -13,11 +13,11 @@ class Data(var x: Foo)
|
||||
class B : Foo() {
|
||||
fun baz(a: Foo, t: Foo, d: Data) {
|
||||
a.bar = t.bar
|
||||
a.foo = t.foo
|
||||
<!INVISIBLE_SETTER!>a.foo<!> = t.foo
|
||||
|
||||
if (d.x is B) {
|
||||
d.x.bar = d.x.bar + ""
|
||||
d.x.foo = d.x.foo + ""
|
||||
<!INVISIBLE_SETTER!>d.x.foo<!> = d.x.foo + ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+12
@@ -25493,6 +25493,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/VisibilityInheritModifier.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("visibleSetterFromSyntheticProperty.kt")
|
||||
public void testVisibleSetterFromSyntheticProperty() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/visibleSetterFromSyntheticProperty.kt");
|
||||
}
|
||||
|
||||
@Nested
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/scopes/classHeader")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@@ -25932,6 +25938,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedCallOnSubClass.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("protectedPropertyInPrimaryConstructor.kt")
|
||||
public void testProtectedPropertyInPrimaryConstructor() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/scopes/protectedVisibility/protectedPropertyInPrimaryConstructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("smartcastOnExtensionReceiver.kt")
|
||||
public void testSmartcastOnExtensionReceiver() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user