FIR: report SMARTCAST_IMPOSSIBLE on inherited alien properties [KT-48101]
This commit is contained in:
committed by
TeamCityServer
parent
0a6e51e47f
commit
fb1eac0985
+6
@@ -28058,6 +28058,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("otherModuleInheritance.kt")
|
||||||
|
public void testOtherModuleInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("protected.kt")
|
@TestMetadata("protected.kt")
|
||||||
public void testProtected() throws Exception {
|
public void testProtected() throws Exception {
|
||||||
|
|||||||
+6
@@ -28058,6 +28058,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("otherModuleInheritance.kt")
|
||||||
|
public void testOtherModuleInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("protected.kt")
|
@TestMetadata("protected.kt")
|
||||||
public void testProtected() throws Exception {
|
public void testProtected() throws Exception {
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor
|
|||||||
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
import org.jetbrains.kotlin.fir.declarations.utils.modality
|
||||||
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.originalIfFakeOverride
|
||||||
|
import org.jetbrains.kotlin.fir.originalOrSelf
|
||||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
@@ -184,7 +186,7 @@ class VariableStorage(private val session: FirSession) {
|
|||||||
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
property.isVar -> PropertyStability.MUTABLE_PROPERTY
|
||||||
property.receiverTypeRef != null -> PropertyStability.PROPERTY_WITH_GETTER
|
property.receiverTypeRef != 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.moduleData.session != session -> PropertyStability.ALIEN_PUBLIC_PROPERTY
|
property.originalOrSelf().moduleData.session != session -> PropertyStability.ALIEN_PUBLIC_PROPERTY
|
||||||
property.modality != Modality.FINAL -> {
|
property.modality != Modality.FINAL -> {
|
||||||
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccess)?.dispatchReceiver ?: return null
|
val dispatchReceiver = (originalFir.unwrapElement() as? FirQualifiedAccess)?.dispatchReceiver ?: return null
|
||||||
val receiverType = dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
|
val receiverType = dispatchReceiver.typeRef.coneTypeSafe<ConeClassLikeType>()?.fullyExpandedType(session) ?: return null
|
||||||
|
|||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// MODULE: m1
|
||||||
|
// FILE: A.kt
|
||||||
|
|
||||||
|
open class Base(val x: Any)
|
||||||
|
open class Generic<T>(val y: T)
|
||||||
|
|
||||||
|
// MODULE: m2(m1)
|
||||||
|
// FILE: B.kt
|
||||||
|
|
||||||
|
class Derived : Base("123") {
|
||||||
|
fun foo() {
|
||||||
|
if (x is String) {
|
||||||
|
<!SMARTCAST_IMPOSSIBLE!>x<!>.length // impossible since `x` is in another module. FE1.0 allows this due to KT-47225
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyGeneric : Generic<Number>(42) {
|
||||||
|
private fun baz(arg: Int) {}
|
||||||
|
fun bar() {
|
||||||
|
if (y is Int) {
|
||||||
|
baz(<!SMARTCAST_IMPOSSIBLE!>y<!>) // impossible since `y` is in another module. FE1.0 allows this due to KT-47225
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// MODULE: m1
|
||||||
|
// FILE: A.kt
|
||||||
|
|
||||||
|
open class Base(val x: Any)
|
||||||
|
open class Generic<T>(val y: T)
|
||||||
|
|
||||||
|
// MODULE: m2(m1)
|
||||||
|
// FILE: B.kt
|
||||||
|
|
||||||
|
class Derived : Base("123") {
|
||||||
|
fun foo() {
|
||||||
|
if (x is String) {
|
||||||
|
<!DEBUG_INFO_SMARTCAST!>x<!>.length // impossible since `x` is in another module. FE1.0 allows this due to KT-47225
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class MyGeneric : Generic<Number>(42) {
|
||||||
|
private fun baz(arg: Int) {}
|
||||||
|
fun bar() {
|
||||||
|
if (y is Int) {
|
||||||
|
baz(<!DEBUG_INFO_SMARTCAST!>y<!>) // impossible since `y` is in another module. FE1.0 allows this due to KT-47225
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
// -- Module: <m1> --
|
||||||
|
package
|
||||||
|
|
||||||
|
public open class Base {
|
||||||
|
public constructor Base(/*0*/ x: kotlin.Any)
|
||||||
|
public final val x: kotlin.Any
|
||||||
|
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 open class Generic</*0*/ T> {
|
||||||
|
public constructor Generic</*0*/ T>(/*0*/ y: T)
|
||||||
|
public final val y: T
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
// -- Module: <m2> --
|
||||||
|
package
|
||||||
|
|
||||||
|
public final class Derived : Base {
|
||||||
|
public constructor Derived()
|
||||||
|
public final override /*1*/ /*fake_override*/ val x: kotlin.Any
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
public final class MyGeneric : Generic<kotlin.Number> {
|
||||||
|
public constructor MyGeneric()
|
||||||
|
public final override /*1*/ /*fake_override*/ val y: kotlin.Number
|
||||||
|
public final fun bar(): kotlin.Unit
|
||||||
|
private final fun baz(/*0*/ arg: kotlin.Int): kotlin.Unit
|
||||||
|
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
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
fun foo1(p: Pair<Int?, Int>): Int {
|
|
||||||
if (p.first != null) return p.first<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
|
||||||
return p.second
|
|
||||||
}
|
|
||||||
|
|
||||||
fun foo2(p: Pair<Int?, Int>): Int {
|
|
||||||
if (p.first != null) return p.first
|
|
||||||
return p.second
|
|
||||||
}
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
// FIR_IDENTICAL
|
||||||
fun foo1(p: Pair<Int?, Int>): Int {
|
fun foo1(p: Pair<Int?, Int>): Int {
|
||||||
if (p.first != null) return p.first!!
|
if (p.first != null) return p.first!!
|
||||||
return p.second
|
return p.second
|
||||||
|
|||||||
Generated
+6
@@ -28148,6 +28148,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("otherModuleInheritance.kt")
|
||||||
|
public void testOtherModuleInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("protected.kt")
|
@TestMetadata("protected.kt")
|
||||||
public void testProtected() throws Exception {
|
public void testProtected() throws Exception {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
fun case_1(x: Pair<*, *>) {
|
fun case_1(x: Pair<*, *>) {
|
||||||
if (x.first !is String) return
|
if (x.first !is String) return
|
||||||
x.first
|
x.first
|
||||||
x.first.length
|
<!SMARTCAST_IMPOSSIBLE!>x.first<!>.length
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -19,5 +19,5 @@ fun case_1(x: Pair<*, *>) {
|
|||||||
fun case_2(x: Pair<*, *>) {
|
fun case_2(x: Pair<*, *>) {
|
||||||
if (x.first !is String?) throw Exception()
|
if (x.first !is String?) throw Exception()
|
||||||
x.first
|
x.first
|
||||||
x.first?.length
|
x.first?.<!UNRESOLVED_REFERENCE!>length<!>
|
||||||
}
|
}
|
||||||
|
|||||||
+6
@@ -28058,6 +28058,12 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
|
|||||||
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModule.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("otherModuleInheritance.kt")
|
||||||
|
public void testOtherModuleInheritance() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/smartCasts/publicVals/otherModuleInheritance.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@TestMetadata("protected.kt")
|
@TestMetadata("protected.kt")
|
||||||
public void testProtected() throws Exception {
|
public void testProtected() throws Exception {
|
||||||
|
|||||||
Reference in New Issue
Block a user