[AllOpen] Private properties can be considered stable even when open
The AllOpen plugin can make private members open. But for private properties, they can be considered stable for smart-casting if they do not have a custom getter. #KT-58049 Fixed
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.fir.resolve.dfa
|
package org.jetbrains.kotlin.fir.resolve.dfa
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
import org.jetbrains.kotlin.fir.FirElement
|
import org.jetbrains.kotlin.fir.FirElement
|
||||||
import org.jetbrains.kotlin.fir.FirSession
|
import org.jetbrains.kotlin.fir.FirSession
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
||||||
@@ -14,6 +15,7 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
|||||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.visibility
|
||||||
import org.jetbrains.kotlin.fir.expressions.*
|
import org.jetbrains.kotlin.fir.expressions.*
|
||||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||||
import org.jetbrains.kotlin.fir.moduleData
|
import org.jetbrains.kotlin.fir.moduleData
|
||||||
@@ -162,6 +164,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
|
|||||||
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
||||||
property.receiverParameter != null -> PropertyStability.PROPERTY_WITH_GETTER
|
property.receiverParameter != null -> PropertyStability.PROPERTY_WITH_GETTER
|
||||||
property.getter.let { it != null && it !is FirDefaultPropertyAccessor } -> PropertyStability.PROPERTY_WITH_GETTER
|
property.getter.let { it != null && it !is FirDefaultPropertyAccessor } -> PropertyStability.PROPERTY_WITH_GETTER
|
||||||
|
property.visibility == Visibilities.Private -> PropertyStability.STABLE_VALUE
|
||||||
property.modality != Modality.FINAL -> {
|
property.modality != Modality.FINAL -> {
|
||||||
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null
|
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccessExpression)?.dispatchReceiver ?: return null
|
||||||
val receiverType = dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
|
val receiverType = dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
|
||||||
|
|||||||
@@ -286,6 +286,9 @@ fun main(args: Array<String>) {
|
|||||||
testClass<AbstractFirPsiBytecodeListingTestForAllOpen> {
|
testClass<AbstractFirPsiBytecodeListingTestForAllOpen> {
|
||||||
model("bytecodeListing", excludedPattern = excludedFirTestdataPattern)
|
model("bytecodeListing", excludedPattern = excludedFirTestdataPattern)
|
||||||
}
|
}
|
||||||
|
testClass<AbstractDiagnosticTestForAllOpenBase> {
|
||||||
|
model("diagnostics", excludedPattern = excludedFirTestdataPattern)
|
||||||
|
}
|
||||||
testClass<AbstractFirLightTreeDiagnosticTestForAllOpen> {
|
testClass<AbstractFirLightTreeDiagnosticTestForAllOpen> {
|
||||||
model("diagnostics", excludedPattern = excludedFirTestdataPattern)
|
model("diagnostics", excludedPattern = excludedFirTestdataPattern)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.allopen
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||||
|
import org.jetbrains.kotlin.test.runners.AbstractDiagnosticTest
|
||||||
|
|
||||||
|
abstract class AbstractDiagnosticTestForAllOpenBase : AbstractDiagnosticTest() {
|
||||||
|
override fun configure(builder: TestConfigurationBuilder) {
|
||||||
|
super.configure(builder)
|
||||||
|
|
||||||
|
with(builder) {
|
||||||
|
useConfigurators(::AllOpenEnvironmentConfigurator)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
|
||||||
|
annotation class AllOpen
|
||||||
|
|
||||||
|
@AllOpen
|
||||||
|
annotation class ConsoleCommands(
|
||||||
|
val <!NON_FINAL_MEMBER_IN_FINAL_CLASS!>value<!>: String = "",
|
||||||
|
val <!NON_FINAL_MEMBER_IN_FINAL_CLASS!>scope<!>: String
|
||||||
|
)
|
||||||
+2
-3
@@ -1,10 +1,9 @@
|
|||||||
// FIR_IDENTICAL
|
|
||||||
// WITH_STDLIB
|
// WITH_STDLIB
|
||||||
|
|
||||||
annotation class AllOpen
|
annotation class AllOpen
|
||||||
|
|
||||||
@AllOpen
|
@AllOpen
|
||||||
annotation class ConsoleCommands(
|
annotation class ConsoleCommands(
|
||||||
val <!NON_FINAL_MEMBER_IN_FINAL_CLASS!>value<!>: String = "",
|
val value: String = "",
|
||||||
val <!NON_FINAL_MEMBER_IN_FINAL_CLASS!>scope<!>: String
|
val scope: String
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
// ISSUE: KT-58049
|
||||||
|
|
||||||
|
annotation class AllOpen
|
||||||
|
|
||||||
|
@AllOpen
|
||||||
|
class Test(
|
||||||
|
val publicProp: String?,
|
||||||
|
protected val protectedProp: String?,
|
||||||
|
internal val internalProp: String?,
|
||||||
|
private val privateProp: String?,
|
||||||
|
) {
|
||||||
|
fun test() {
|
||||||
|
checkNotNull(publicProp)
|
||||||
|
checkNotNull(protectedProp)
|
||||||
|
checkNotNull(internalProp)
|
||||||
|
checkNotNull(privateProp)
|
||||||
|
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>publicProp<!>.length)
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>protectedProp<!>.length)
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>internalProp<!>.length)
|
||||||
|
println(privateProp.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
// WITH_STDLIB
|
||||||
|
// ISSUE: KT-58049
|
||||||
|
|
||||||
|
annotation class AllOpen
|
||||||
|
|
||||||
|
@AllOpen
|
||||||
|
class Test(
|
||||||
|
val publicProp: String?,
|
||||||
|
protected val protectedProp: String?,
|
||||||
|
internal val internalProp: String?,
|
||||||
|
private val privateProp: String?,
|
||||||
|
) {
|
||||||
|
fun test() {
|
||||||
|
checkNotNull(publicProp)
|
||||||
|
checkNotNull(protectedProp)
|
||||||
|
checkNotNull(internalProp)
|
||||||
|
checkNotNull(privateProp)
|
||||||
|
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>publicProp<!>.length)
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>protectedProp<!>.length)
|
||||||
|
println(<!SMARTCAST_IMPOSSIBLE!>internalProp<!>.length)
|
||||||
|
println(<!DEBUG_INFO_SMARTCAST!>privateProp<!>.length)
|
||||||
|
}
|
||||||
|
}
|
||||||
Generated
+38
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2023 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.allopen;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.GenerateTestsKt}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("plugins/allopen/testData/diagnostics")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
public class DiagnosticTestForAllOpenBaseGenerated extends AbstractDiagnosticTestForAllOpenBase {
|
||||||
|
@Test
|
||||||
|
public void testAllFilesPresentInDiagnostics() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("plugins/allopen/testData/diagnostics"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("kt54260.kt")
|
||||||
|
public void testKt54260() throws Exception {
|
||||||
|
runTest("plugins/allopen/testData/diagnostics/kt54260.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("smartcast.kt")
|
||||||
|
public void testSmartcast() throws Exception {
|
||||||
|
runTest("plugins/allopen/testData/diagnostics/smartcast.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
@@ -29,4 +29,10 @@ public class FirLightTreeDiagnosticTestForAllOpenGenerated extends AbstractFirLi
|
|||||||
public void testKt54260() throws Exception {
|
public void testKt54260() throws Exception {
|
||||||
runTest("plugins/allopen/testData/diagnostics/kt54260.kt");
|
runTest("plugins/allopen/testData/diagnostics/kt54260.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("smartcast.kt")
|
||||||
|
public void testSmartcast() throws Exception {
|
||||||
|
runTest("plugins/allopen/testData/diagnostics/smartcast.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Generated
+6
@@ -29,4 +29,10 @@ public class FirPsiDiagnosticTestForAllOpenGenerated extends AbstractFirPsiDiagn
|
|||||||
public void testKt54260() throws Exception {
|
public void testKt54260() throws Exception {
|
||||||
runTest("plugins/allopen/testData/diagnostics/kt54260.kt");
|
runTest("plugins/allopen/testData/diagnostics/kt54260.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("smartcast.kt")
|
||||||
|
public void testSmartcast() throws Exception {
|
||||||
|
runTest("plugins/allopen/testData/diagnostics/smartcast.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user