Fix type parameter bound check in expect-actual checker

Also make TypeParameterUpperBounds a "strong" incompatibility, meaning
that non-actual members from platform module are _not_ going to be
matched to the expected members if this incompatibility exists between
them, and therefore NO_ACTUAL_FOR_EXPECT will be reported on the
expected declaration, instead of ACTUAL_MISSING on the platform member.
This is needed because the difference in type parameter upper bounds can
have effect on the function signature on the platform (e.g. on JVM,
Array<T> -> T[], but Array<T> -> Comparable[] if T : Comparable<T>), and
it would be incorrect to report ACTUAL_MISSING on the member that has
nothing to do with the expected declaration that happens to coincide
with it in everything except type parameter bounds

 #KT-21864 Fixed
This commit is contained in:
Alexander Udalov
2018-01-08 15:35:59 +01:00
parent 8c6b140865
commit f198a28276
11 changed files with 224 additions and 3 deletions
@@ -50,6 +50,24 @@ The following declaration is incompatible because number of type parameters is d
expect fun <T> f7()
^
compiler/testData/multiplatform/incompatibleCallables/common.kt:19:12: error: expected function 'f11' has no actual declaration in module
The following declaration is incompatible because upper bounds of type parameters are different:
public actual fun <T : Annotation> f11(): Unit
expect fun <T : Number> f11()
^
compiler/testData/multiplatform/incompatibleCallables/common.kt:20:12: error: expected function 'f12' has no actual declaration in module
The following declaration is incompatible because upper bounds of type parameters are different:
public actual fun <U : MutableList<out String>> f12(): Unit
expect fun <U : MutableList<String>> f12()
^
compiler/testData/multiplatform/incompatibleCallables/common.kt:21:12: error: expected function 'f13' has no actual declaration in module
The following declaration is incompatible because upper bounds of type parameters are different:
public actual fun <A, B : Comparable<B>> f13(): Unit
expect fun <A, B : Comparable<A>> f13()
^
compiler/testData/multiplatform/incompatibleCallables/common.kt:32:15: error: expected function 'f21' has no actual declaration in module
The following declaration is incompatible because parameter types are different:
public actual fun f21(c: Unit.() -> Unit): Unit
@@ -122,6 +140,24 @@ The following declaration is incompatible because visibility is different:
internal actual fun f10() {}
^
compiler/testData/multiplatform/incompatibleCallables/jvm.kt:19:12: error: actual function 'f11' has no corresponding expected declaration
The following declaration is incompatible because upper bounds of type parameters are different:
public expect fun <T : Number> f11(): Unit
actual fun <T : Annotation> f11() {}
^
compiler/testData/multiplatform/incompatibleCallables/jvm.kt:20:12: error: actual function 'f12' has no corresponding expected declaration
The following declaration is incompatible because upper bounds of type parameters are different:
public expect fun <U : MutableList<String>> f12(): Unit
actual fun <U : MutableList<out String>> f12() {}
^
compiler/testData/multiplatform/incompatibleCallables/jvm.kt:21:12: error: actual function 'f13' has no corresponding expected declaration
The following declaration is incompatible because upper bounds of type parameters are different:
public expect fun <A, B : Comparable<A>> f13(): Unit
actual fun <A, B : Comparable<B>> f13() {}
^
compiler/testData/multiplatform/incompatibleCallables/jvm.kt:23:19: error: actual function 'f14' has no corresponding expected declaration
The following declaration is incompatible because some type parameter is reified in one declaration and non-reified in the other:
public expect inline fun <X> f14(): Unit