[Expect/Actual] Add testdata on hierarchical expect/actual matching

This commit is contained in:
Dmitry Savvinov
2019-04-23 20:59:07 +03:00
parent cac326bf4a
commit 54b8f9da28
70 changed files with 508 additions and 20 deletions
@@ -0,0 +1,3 @@
package sample
actual class A
@@ -0,0 +1,8 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE left { platform=[JVM, JS, Native] }
MODULE right { platform=[JVM, JS, Native] }
MODULE bottom { platform=[JVM] }
left -> top { kind=DEPENDS_ON }
right -> top { kind=DEPENDS_ON }
bottom -> left, right { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
package sample
expect class A
@@ -0,0 +1,6 @@
package sample
fun main() {
ActualizedInLeft()
ActualizedInRight()
}
@@ -0,0 +1,8 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE left { platform=[JVM, JS, Native] }
MODULE right { platform=[JVM, JS, Native] }
MODULE bottom { platform=[JVM] }
left -> top { kind=DEPENDS_ON }
right -> top { kind=DEPENDS_ON }
bottom -> left, right { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
package sample
actual class ActualizedInLeft
@@ -0,0 +1,3 @@
package sample
actual class ActualizedInRight
@@ -0,0 +1,4 @@
package sample
expect class ActualizedInLeft
expect class ActualizedInRight
@@ -0,0 +1,16 @@
package sample
actual class A {
actual fun foo(): Int = 45
fun fromBottom(): Int = 0
}
fun main() {
A().foo()
// Any behaviour is acceptable, as the code is erroneous.
// At the time of writing this test, we resolve to nearest A, i.e.
// 'fromBottom' is resolved, and 'fromLeft' is not.
A().<!UNRESOLVED_REFERENCE("fromLeft")!>fromLeft<!>()
A().fromBottom()
}
@@ -0,0 +1,8 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE left { platform=[JVM, JS, Native] }
MODULE right { platform=[JVM, JS, Native] }
MODULE bottom { platform=[JVM] }
left -> top { kind=DEPENDS_ON }
right -> top { kind=DEPENDS_ON }
bottom -> left, right { kind=DEPENDS_ON }
@@ -0,0 +1,6 @@
package sample
actual class A /* Left */ {
actual fun foo(): Int = 42
fun fromLeft(): String = ""
}
@@ -0,0 +1,5 @@
package sample
expect class <!AMBIGUOUS_ACTUALS("Class 'A'", "bottom for JVM, left")!>A<!> {
fun <!AMBIGUOUS_ACTUALS("Function 'foo'", "bottom for JVM, left")!>foo<!>(): Int
}
@@ -0,0 +1,7 @@
package sample
fun main() {
A().foo()
// fromLeft should be resolved, because 'left' comes first in dependencies order!
A().fromLeft()
}
@@ -0,0 +1,8 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE left { platform=[JVM, JS, Native] }
MODULE right { platform=[JVM, JS, Native] }
MODULE bottom { platform=[JVM] }
left -> top { kind=DEPENDS_ON }
right -> top { kind=DEPENDS_ON }
bottom -> left, right { kind=DEPENDS_ON }
@@ -0,0 +1,6 @@
package sample
actual class A /* Left */ {
actual fun foo(): Int = 42
fun fromLeft(): String = ""
}
@@ -0,0 +1,5 @@
package sample
actual class A /* Right */ {
actual fun foo(): Int = 100500
}
@@ -0,0 +1,5 @@
package sample
expect class A {
fun foo(): Int
}
@@ -0,0 +1,8 @@
actual class A
// Error: ACTUAL_WITHOUT_EXPECT, becuase we shouldn't see expects through usual dependencies
actual class <!ACTUAL_WITHOUT_EXPECT("Actual class 'B'", "")!>B<!>
// OK: though we can't actualize B, we can see it and use it.
fun useB(<!UNUSED_PARAMETER("b")!>b<!>: B) {
}
@@ -0,0 +1,8 @@
actual class A
// Error: ACTUAL_WITHOUT_EXPECT, becuase we shouldn't see expects through usual dependencies
actual class <!ACTUAL_WITHOUT_EXPECT("Actual class 'B'", "")!>B<!>
// OK: though we can't actualize B, we can see it and use it.
fun useB(<!UNUSED_PARAMETER("b")!>b<!>: B) {
}
@@ -0,0 +1 @@
expect class <!NO_ACTUAL_FOR_EXPECT("class 'B'", "b-common", "")!>B<!>
@@ -0,0 +1,9 @@
MODULE a-common { platform=[JVM, JS, Native] }
MODULE a-js { platform=[JS] }
MODULE a-jvm { platform=[JVM] }
MODULE b-common { platform=[JVM, JS, Native] }
a-js -> a-common { kind=DEPENDS_ON }
a-jvm -> a-common { kind=DEPENDS_ON }
a-common -> b-common { kind=DEPENDENCY }
@@ -0,0 +1,3 @@
package foo
actual class A
@@ -0,0 +1,6 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE middle { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
middle -> top { kind=DEPENDS_ON }
bottom -> middle { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
package foo
actual class A
@@ -0,0 +1,3 @@
package foo
expect class <!AMBIGUOUS_ACTUALS("Class 'A'", "bottom for JVM, middle")!>A<!>
@@ -0,0 +1,6 @@
package foo
class <!ACTUAL_MISSING!>ActualInMiddleCompatibleInBottom<!>
actual class CompatibleInMiddleActualInBottom
class <!ACTUAL_MISSING!>CompatibleInMiddleAndBottom<!>
@@ -0,0 +1,6 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE middle { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
middle -> top { kind=DEPENDS_ON }
bottom -> middle { kind=DEPENDS_ON }
@@ -0,0 +1,6 @@
package foo
actual class ActualInMiddleCompatibleInBottom
class <!ACTUAL_MISSING!>CompatibleInMiddleActualInBottom<!>
class <!ACTUAL_MISSING!>CompatibleInMiddleAndBottom<!>
@@ -0,0 +1,6 @@
package foo
expect class <!AMBIGUOUS_ACTUALS("Class 'ActualInMiddleCompatibleInBottom'", "bottom for JVM, middle")!>ActualInMiddleCompatibleInBottom<!>
expect class <!AMBIGUOUS_ACTUALS("Class 'CompatibleInMiddleActualInBottom'", "bottom for JVM, middle")!>CompatibleInMiddleActualInBottom<!>
expect class <!AMBIGUOUS_ACTUALS("Class 'CompatibleInMiddleAndBottom'", "bottom for JVM, middle")!>CompatibleInMiddleAndBottom<!>
@@ -0,0 +1,3 @@
package foo
<!ACTUAL_WITHOUT_EXPECT("Class 'A'", " The following declaration is incompatible because visibility is different: public final expect class A ")!>private<!> class A
@@ -0,0 +1,6 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE middle { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
middle -> top { kind=DEPENDS_ON }
bottom -> middle { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
package foo
expect class <!AMBIGUOUS_ACTUALS("Class 'A'", "middle, bottom for JVM")!>A<!>
@@ -0,0 +1,3 @@
package foo
actual fun foo<!ACTUAL_WITHOUT_EXPECT("Actual function 'foo'", " The following declaration is incompatible because number of value parameters is different: public expect fun foo(): Int ")!>(x: Int)<!>: Int = x
@@ -0,0 +1,6 @@
MODULE top { platform=[JVM, JS, Native] }
MODULE middle { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
middle -> top { kind=DEPENDS_ON }
bottom -> middle { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
package foo
actual fun foo(): Int = 42
@@ -0,0 +1,3 @@
package foo
expect fun foo(): Int
@@ -0,0 +1 @@
actual class <!AMBIGUOUS_EXPECTS("Actual class 'A'", "right, left")!>A<!>
@@ -0,0 +1,6 @@
MODULE right { platform=[JVM, Native] }
MODULE left { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
bottom -> right { kind=DEPENDS_ON }
bottom -> left { kind=DEPENDS_ON }
@@ -0,0 +1,3 @@
// Note that here we have no ambiguity, becuase we don't consider
// declarations without 'expect' as potential weakly-compatible 'expect'-counterpart
actual class A
@@ -0,0 +1,6 @@
MODULE right { platform=[JVM, Native] }
MODULE left { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
bottom -> right { kind=DEPENDS_ON }
bottom -> left { kind=DEPENDS_ON }
@@ -0,0 +1 @@
expect class <!AMBIGUOUS_ACTUALS("Class 'A'", "bottom.kt, right.kt")!>A<!>
@@ -0,0 +1,6 @@
MODULE right { platform=[JVM, Native] }
MODULE left { platform=[JVM, JS] }
MODULE bottom { platform=[JVM] }
bottom -> right { kind=DEPENDS_ON }
bottom -> left { kind=DEPENDS_ON }
@@ -0,0 +1 @@
expect fun foo<!NO_ACTUAL_FOR_EXPECT("function 'foo'", "bottom for JVM", " The following declaration is incompatible because number of value parameters is different: public actual fun foo(): Int ")!>(x: Int)<!>: Int
@@ -0,0 +1,6 @@
package foo
expect class ExpectInCommonActualInMiddle
expect class ExpectInCommonActualInPlatforms
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInCommonWithoutActual'", "js for JS", ""), NO_ACTUAL_FOR_EXPECT("class 'ExpectInCommonWithoutActual'", "jvm for JVM", "")!>ExpectInCommonWithoutActual<!>
@@ -0,0 +1,8 @@
MODULE common { platform=[JVM, JS, Native] }
MODULE jvmAndJs { platform=[JVM, JS] }
MODULE jvm { platform=[JVM] }
MODULE js { platform=[JS] }
jvm -> jvmAndJs { kind=DEPENDS_ON }
js -> jvmAndJs { kind=DEPENDS_ON }
jvmAndJs -> common { kind=DEPENDS_ON }
@@ -0,0 +1,10 @@
package foo
actual class ExpectInCommonActualInPlatforms
actual class ExpectInMiddleActualInPlatforms
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInJsWithoutActual'", "js for JS", "")!>ExpectInJsWithoutActual<!>
expect class ExpectInJsActualInJs
actual class ExpectInJsActualInJs
@@ -0,0 +1,9 @@
package foo
actual class ExpectInCommonActualInPlatforms
actual class ExpectInMiddleActualInPlatforms
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInJvmWithoutActual'", "jvm for JVM", "")!>ExpectInJvmWithoutActual<!>
expect class ExpectInJvmActualInJvm
actual class ExpectInJvmActualInJvm
@@ -0,0 +1,7 @@
package foo
actual class ExpectInCommonActualInMiddle
expect class ExpectInMiddleActualInPlatforms
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInMiddleWithoutActual'", "js for JS", ""), NO_ACTUAL_FOR_EXPECT("class 'ExpectInMiddleWithoutActual'", "jvm for JVM", "")!>ExpectInMiddleWithoutActual<!>
@@ -0,0 +1,4 @@
package foo
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInCommonActualInJsOnly'", "jvm for JVM", "")!>ExpectInCommonActualInJsOnly<!>
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInCommonActualInJvmOnly'", "js for JS", "")!>ExpectInCommonActualInJvmOnly<!>
@@ -0,0 +1,8 @@
MODULE common { platform=[JVM, JS, Native] }
MODULE jvmAndJs { platform=[JVM, JS] }
MODULE jvm { platform=[JVM] }
MODULE js { platform=[JS] }
jvm -> jvmAndJs { kind=DEPENDS_ON }
js -> jvmAndJs { kind=DEPENDS_ON }
jvmAndJs -> common { kind=DEPENDS_ON }
@@ -0,0 +1,4 @@
package foo
actual class ExpectInCommonActualInJsOnly
actual class ExpectInMiddleActualInJsOnly
@@ -0,0 +1,4 @@
package foo
actual class ExpectInCommonActualInJvmOnly
actual class ExpectInMiddleActualInJvmOnly
@@ -0,0 +1,4 @@
package foo
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInMiddleActualInJsOnly'", "jvm for JVM", "")!>ExpectInMiddleActualInJsOnly<!>
expect class <!NO_ACTUAL_FOR_EXPECT("class 'ExpectInMiddleActualInJvmOnly'", "js for JS", "")!>ExpectInMiddleActualInJvmOnly<!>