[KMP] Allow matching expect ctorless final classes to objects

both directly and via typealias.

This is a possible fix to KT-59747
This commit is contained in:
marat.akhin
2023-07-20 18:16:06 +02:00
committed by Space Team
parent 6df9ce23f7
commit ae4fab8483
30 changed files with 1273 additions and 1 deletions
@@ -0,0 +1,42 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: ANY
// FIR status: expect/actual in the same module
// also used as a workaround for no multi-module support in K1 box tests
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// FILE: actual.kt
actual object TestResult {
fun doTest(): TestResult = this
}
actual fun createTestResult(): TestResult = TestResult
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()
@@ -0,0 +1,48 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: ANY
// FIR status: expect/actual in the same module
// also used as a workaround for no multi-module support in K1 box tests
// TARGET_BACKEND: JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// FILE: js.kt
import kotlin.js.Promise
class PromiseOfUnit(executor: (resolve: (Unit) -> Unit, reject: (Throwable) -> Unit) -> Unit) : Promise<Unit>(executor)
actual typealias TestResult = PromiseOfUnit
actual fun createTestResult(): TestResult = PromiseOfUnit {
resolve, reject ->
}
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()
@@ -0,0 +1,40 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K2: ANY
// FIR status: expect/actual in the same module
// also used as a workaround for no multi-module support in K1 box tests
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// FILE: actual.kt
actual typealias TestResult = Unit
actual fun createTestResult(): TestResult = TestResult
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()
@@ -0,0 +1,42 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// MODULE: common
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// MODULE: actual()()(common)
// FILE: actual.kt
actual object TestResult {
fun doTest(): TestResult = this
}
actual fun createTestResult(): TestResult = TestResult
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()
@@ -0,0 +1,48 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// TARGET_BACKEND: JS, JS_IR, JS_IR_ES6
// WITH_STDLIB
// MODULE: common
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// MODULE: js()()(common)
// FILE: js.kt
import kotlin.js.Promise
class PromiseOfUnit(executor: (resolve: (Unit) -> Unit, reject: (Throwable) -> Unit) -> Unit) : Promise<Unit>(executor)
actual typealias TestResult = PromiseOfUnit
actual fun createTestResult(): TestResult = PromiseOfUnit {
resolve, reject ->
}
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()
@@ -0,0 +1,40 @@
// LANGUAGE: +MultiPlatformProjects
// IGNORE_BACKEND_K1: ANY
// MODULE: common
// FILE: common.kt
expect class TestResult
expect fun createTestResult(): TestResult
fun commonBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "c01"
if (tr.hashCode() != tr2.hashCode()) return "c02"
if (tr.toString() != tr2.toString()) return "c03"
return "O"
}
// MODULE: actual()()(common)
// FILE: actual.kt
actual typealias TestResult = Unit
actual fun createTestResult(): TestResult = TestResult
fun platformBox(): String {
val tr = createTestResult()
val tr2 = if (true) tr else createTestResult()
if (tr != tr2) return "p01"
if (tr.hashCode() != tr2.hashCode()) return "p02"
if (tr.toString() != tr2.toString()) return "p03"
return "K"
}
fun box() = commonBox() + platformBox()