[MPP] Allow smart casts for properties from dependsOn modules
Smartcasts for public properties from different module are not stable because module declaring a property in general can be compiled separately from the module using it. However, if client module has dependsOn relation with declaring module their simultaneous compilation is guaranteed which makes this smart cast safe. Cache all transitive 'expected by' modules in module dependencies. Extend test to check smart casts are allowed for properties from transitive 'expected by' dependencies and prohibited otherwise. ^KT-42754 Fixed
This commit is contained in:
-5
@@ -1,5 +0,0 @@
|
||||
data class CommonDataClass(val property: CommonObject?)
|
||||
|
||||
object CommonObject {
|
||||
fun doSomething() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
data class CommonDataClass1(val property: CommonObject1?)
|
||||
|
||||
object CommonObject1 {
|
||||
fun doSomething() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
data class CommonDataClass2(val property: CommonObject2?)
|
||||
|
||||
object CommonObject2 {
|
||||
fun doSomething() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
data class CommonDataClass3(val property: CommonObject3?)
|
||||
|
||||
object CommonObject3 {
|
||||
fun doSomething() {}
|
||||
}
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
data class CommonDataClass4(val property: CommonObject4?)
|
||||
|
||||
object CommonObject4 {
|
||||
fun doSomething() {}
|
||||
}
|
||||
+9
-3
@@ -1,7 +1,13 @@
|
||||
MODULE common { platform=[JVM, JS, Native] }
|
||||
MODULE common1 { platform=[JVM, JS, Native] }
|
||||
MODULE common2 { platform=[JVM, JS, Native] }
|
||||
MODULE common3 { platform=[JVM, JS, Native] }
|
||||
MODULE common4 { platform=[JVM, JS, Native] }
|
||||
MODULE jvm1 { platform=[JVM] }
|
||||
MODULE jvm2 { platform=[JVM] }
|
||||
|
||||
jvm1 -> common { kind=DEPENDS_ON }
|
||||
jvm2 -> common { kind=DEPENDS_ON }
|
||||
common2 -> common1 { kind=DEPENDS_ON }
|
||||
common3 -> common1 { kind=DEPENDS_ON }
|
||||
common4 -> common2, common3 { kind=DEPENDS_ON }
|
||||
jvm1 -> common4 { kind=DEPENDS_ON }
|
||||
jvm2 -> common4 { kind=DEPENDS_ON }
|
||||
jvm2 -> jvm1 { kind=DEPENDENCY }
|
||||
|
||||
+17
-5
@@ -1,9 +1,21 @@
|
||||
fun test(fromCommon: CommonDataClass, fromJvm: JvmDataClass) {
|
||||
if (fromCommon.property != null) {
|
||||
<!SMARTCAST_IMPOSSIBLE!>fromCommon.property<!>.doSomething()
|
||||
fun test(c1: CommonDataClass1, c2: CommonDataClass2, c3: CommonDataClass3, c4: CommonDataClass4, jvm: JvmDataClass) {
|
||||
if (c1.property != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>c1.property<!>.doSomething()
|
||||
}
|
||||
|
||||
if (fromJvm.property != null) {
|
||||
<!SMARTCAST_IMPOSSIBLE!>fromJvm.property<!>.doSomething()
|
||||
if (c2.property != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>c2.property<!>.doSomething()
|
||||
}
|
||||
|
||||
if (c3.property != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>c3.property<!>.doSomething()
|
||||
}
|
||||
|
||||
if (c4.property != null) {
|
||||
<!DEBUG_INFO_SMARTCAST!>c4.property<!>.doSomething()
|
||||
}
|
||||
|
||||
if (jvm.property != null) {
|
||||
<!SMARTCAST_IMPOSSIBLE!>jvm.property<!>.doSomething()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user