[FIR] Ignore smartcast for non-final members from Java, ^KT-50219 Fixed
This commit is contained in:
+6
@@ -27987,6 +27987,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noSmartcastForNonFinalMembersFromJava.kt")
|
||||
public void testNoSmartcastForNonFinalMembersFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noSmartcastForNonFinalMembersFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noUnnecessarySmartCastForReceiver.kt")
|
||||
public void testNoUnnecessarySmartCastForReceiver() throws Exception {
|
||||
|
||||
+6
@@ -27987,6 +27987,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noSmartcastForNonFinalMembersFromJava.kt")
|
||||
public void testNoSmartcastForNonFinalMembersFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noSmartcastForNonFinalMembersFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noUnnecessarySmartCastForReceiver.kt")
|
||||
public void testNoUnnecessarySmartCastForReceiver() throws Exception {
|
||||
|
||||
+6
@@ -27987,6 +27987,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noSmartcastForNonFinalMembersFromJava.kt")
|
||||
public void testNoSmartcastForNonFinalMembersFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noSmartcastForNonFinalMembersFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noUnnecessarySmartCastForReceiver.kt")
|
||||
public void testNoUnnecessarySmartCastForReceiver() throws Exception {
|
||||
|
||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.fir.contracts.description.ConeConstantReference
|
||||
import org.jetbrains.kotlin.fir.contracts.description.ConeReturnsEffectDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isLocal
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.fir.declarations.FirAnonymousObject
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isFinal
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirNoReceiverExpression
|
||||
@@ -179,6 +180,7 @@ class VariableStorageImpl(private val session: FirSession) : VariableStorage() {
|
||||
}
|
||||
if (originalFir is FirThisReceiverExpression) return PropertyStability.STABLE_VALUE
|
||||
if (this !is FirVariableSymbol<*>) return null
|
||||
if (this is FirFieldSymbol && !this.isFinal) return PropertyStability.MUTABLE_PROPERTY
|
||||
|
||||
val property = this.fir as? FirProperty ?: return PropertyStability.STABLE_VALUE
|
||||
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// FIR_IDENTICAL
|
||||
// KT-50219
|
||||
|
||||
// FILE: Base.java
|
||||
public class Base {
|
||||
protected String field;
|
||||
protected final String finalField = "finalFieldValue";
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
class Derived : Base() {
|
||||
fun foo() {
|
||||
if (field == null) {
|
||||
field.length
|
||||
}
|
||||
|
||||
if (finalField == null) {
|
||||
finalField<!UNSAFE_CALL!>.<!>length
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package
|
||||
|
||||
public open class Base {
|
||||
public constructor Base()
|
||||
protected/*protected and package*/ final var field: kotlin.String!
|
||||
protected/*protected and package*/ final val finalField: kotlin.String! = "finalFieldValue"
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class Derived : Base {
|
||||
public constructor Derived()
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ var field: kotlin.String!
|
||||
protected/*protected and package*/ final override /*1*/ /*fake_override*/ val finalField: kotlin.String!
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
Generated
+6
@@ -28077,6 +28077,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noErrorCheckForPackageLevelVal.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noSmartcastForNonFinalMembersFromJava.kt")
|
||||
public void testNoSmartcastForNonFinalMembersFromJava() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/smartCasts/noSmartcastForNonFinalMembersFromJava.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("noUnnecessarySmartCastForReceiver.kt")
|
||||
public void testNoUnnecessarySmartCastForReceiver() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user