Skip to content

Commit 28f7fcb

Browse files
authored
Uncomment multi-module inheritance tests (#2116)
Given that KT-49865 is not reproducible on 1.7.20+, uncommenting these tests would help catch bugs like https://youtrack.jetbrains.com/issue/KT-55180 Note: there is still a compiler crash on JS Legacy, but given that 1.8.0 would deprecate it, this can be investigated separately
1 parent ea69eb3 commit 28f7fcb

File tree

4 files changed

+105
-103
lines changed

4 files changed

+105
-103
lines changed

integration-test/gradle.properties

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mainKotlinVersion=1.7.20
66
mainLibVersion=1.5.0-SNAPSHOT
77

88
kotlin.code.style=official
9-
kotlin.js.compiler=both
9+
kotlin.js.compiler=ir
1010

1111
gradle_node_version = 1.2.0
1212
node_version = 8.9.3
@@ -15,4 +15,7 @@ mocha_version = 4.1.0
1515
mocha_teamcity_reporter_version = 2.2.2
1616
source_map_support_version = 0.5.3
1717

18+
# Uncommend & insert path to local Native distribution if you want to test with SNAPSHOT compiler
19+
#kotlin.native.home=
20+
1821
#org.jetbrains.kotlin.native.jvmArgs=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5007

integration-test/src/commonTest/kotlin/sample/MultiFileHierarchyModuleB.kt

Lines changed: 55 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,58 @@ import kotlinx.serialization.Serializable
55

66
@Serializable
77
class EmptyClassB : EmptyBase()
8-
// TODO: Uncomment when https://youtrack.jetbrains.com/issue/KT-49865 is resolved
9-
//
10-
//@Serializable
11-
//open class Car : Vehicle() {
12-
// var maxSpeed: Int = 100
13-
//
14-
// override fun equals(other: Any?): Boolean {
15-
// if (this === other) return true
16-
// if (other !is Car) return false
17-
// if (name != other.name) return false
18-
// if (color != other.color) return false
19-
// if (maxSpeed != other.maxSpeed) return false
20-
//
21-
// return true
22-
// }
23-
//
24-
// override fun hashCode(): Int {
25-
// return maxSpeed.hashCode()
26-
// }
27-
//
28-
// override fun toString(): String {
29-
// return "Car(name=$name, color=$color, maxSpeed=$maxSpeed)"
30-
// }
31-
//}
32-
//
33-
//@Serializable
34-
//data class TestSnippet(
35-
// @SerialName("experiments") val experiments: List<String>
36-
//) : Snippet("test", "aaa")
37-
//
38-
//@Serializable
39-
//data class ScreenSnippet(
40-
// @SerialName("name") val name: String,
41-
// @SerialName("uuid") val uuid: String? = null,
42-
// @SerialName("source") val source: String? = null
43-
//) : Snippet("screen", "aaa")
44-
//
45-
//@Serializable
46-
//class NotInConstructorTest : NotInConstructorBase() {
47-
// val c = "val c"
48-
//
49-
// override fun equals(other: Any?): Boolean {
50-
// if (this === other) return true
51-
// if (other !is NotInConstructorTest) return false
52-
//
53-
// if (a != other.a) return false
54-
// if (b != other.b) return false
55-
// if (c != other.c) return false
56-
//
57-
// return true
58-
// }
59-
//
60-
// override fun hashCode(): Int {
61-
// return a.hashCode() * 31 + b.hashCode() * 31 + c.hashCode()
62-
// }
63-
//}
8+
9+
@Serializable
10+
open class Car : Vehicle() {
11+
var maxSpeed: Int = 100
12+
13+
override fun equals(other: Any?): Boolean {
14+
if (this === other) return true
15+
if (other !is Car) return false
16+
if (name != other.name) return false
17+
if (color != other.color) return false
18+
if (maxSpeed != other.maxSpeed) return false
19+
20+
return true
21+
}
22+
23+
override fun hashCode(): Int {
24+
return maxSpeed.hashCode()
25+
}
26+
27+
override fun toString(): String {
28+
return "Car(name=$name, color=$color, maxSpeed=$maxSpeed)"
29+
}
30+
}
31+
32+
@Serializable
33+
data class TestSnippet(
34+
@SerialName("experiments") val experiments: List<String>
35+
) : Snippet("test", "aaa")
36+
37+
@Serializable
38+
data class ScreenSnippet(
39+
@SerialName("name") val name: String,
40+
@SerialName("uuid") val uuid: String? = null,
41+
@SerialName("source") val source: String? = null
42+
) : Snippet("screen", "aaa")
43+
44+
@Serializable
45+
class NotInConstructorTest : NotInConstructorBase() {
46+
val c = "val c"
47+
48+
override fun equals(other: Any?): Boolean {
49+
if (this === other) return true
50+
if (other !is NotInConstructorTest) return false
51+
52+
if (a != other.a) return false
53+
if (b != other.b) return false
54+
if (c != other.c) return false
55+
56+
return true
57+
}
58+
59+
override fun hashCode(): Int {
60+
return a.hashCode() * 31 + b.hashCode() * 31 + c.hashCode()
61+
}
62+
}

integration-test/src/commonTest/kotlin/sample/MultiFileHierarchyTest.kt

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -28,49 +28,49 @@ class AbstractBaseTest {
2828
val parsed: EmptyClassB = Json.decodeFromString(EmptyClassB.serializer(), serialized)
2929
}
3030

31-
// @Test
32-
// fun testCrossModuleInheritance() {
33-
// val json = Json { allowStructuredMapKeys = true; encodeDefaults = true }
34-
//
35-
// val car = Car()
36-
// car.maxSpeed = 100
37-
// car.name = "ford"
38-
// val s = json.encodeToString(Car.serializer(), car)
39-
// assertEquals("""{"name":"ford","color":null,"maxSpeed":100}""", s)
40-
// val restoredCar = json.decodeFromString(Car.serializer(), s)
41-
// assertEquals(car, restoredCar)
42-
// }
43-
//
44-
// @Test
45-
// fun testCrossModuleAbstractInheritance() {
46-
// val snippetModule = SerializersModule {
47-
// polymorphic(Snippet::class) {
48-
// subclass(ScreenSnippet.serializer())
49-
// subclass(TestSnippet.serializer())
50-
// }
51-
// }
52-
//
53-
// val json = Json {
54-
// serializersModule = snippetModule
55-
// encodeDefaults = true
56-
// }
57-
//
58-
// val testSnippet = TestSnippet(emptyList())
59-
// val screenSnippet = ScreenSnippet("one", "two", "three")
60-
// val s = json.encodeToString(TestSnippet.serializer(), testSnippet)
61-
// assertEquals(testSnippet, json.decodeFromString(TestSnippet.serializer(), s))
62-
// assertEquals("""{"objectFieldName":"test","aaa":"aaa","experiments":[]}""",
63-
// json.encodeToString(TestSnippet.serializer(), testSnippet)
64-
// )
65-
// assertStringFormAndRestored("""{"objectFieldName":"screen","aaa":"aaa","name":"one","uuid":"two","source":"three"}""",
66-
// screenSnippet,
67-
// ScreenSnippet.serializer(),
68-
// json
69-
// )
70-
// }
71-
//
72-
// @Test
73-
// fun testPropertiesNotInConstructor() {
74-
// assertStringFormAndRestored("""{"b":"val b","a":"val a","c":"val c"}""", NotInConstructorTest(), NotInConstructorTest.serializer())
75-
// }
31+
@Test
32+
fun testCrossModuleInheritance() {
33+
val json = Json { allowStructuredMapKeys = true; encodeDefaults = true }
34+
35+
val car = Car()
36+
car.maxSpeed = 100
37+
car.name = "ford"
38+
val s = json.encodeToString(Car.serializer(), car)
39+
assertEquals("""{"name":"ford","color":null,"maxSpeed":100}""", s)
40+
val restoredCar = json.decodeFromString(Car.serializer(), s)
41+
assertEquals(car, restoredCar)
42+
}
43+
44+
@Test
45+
fun testCrossModuleAbstractInheritance() {
46+
val snippetModule = SerializersModule {
47+
polymorphic(Snippet::class) {
48+
subclass(ScreenSnippet.serializer())
49+
subclass(TestSnippet.serializer())
50+
}
51+
}
52+
53+
val json = Json {
54+
serializersModule = snippetModule
55+
encodeDefaults = true
56+
}
57+
58+
val testSnippet = TestSnippet(emptyList())
59+
val screenSnippet = ScreenSnippet("one", "two", "three")
60+
val s = json.encodeToString(TestSnippet.serializer(), testSnippet)
61+
assertEquals(testSnippet, json.decodeFromString(TestSnippet.serializer(), s))
62+
assertEquals("""{"objectFieldName":"test","aaa":"aaa","experiments":[]}""",
63+
json.encodeToString(TestSnippet.serializer(), testSnippet)
64+
)
65+
assertStringFormAndRestored("""{"objectFieldName":"screen","aaa":"aaa","name":"one","uuid":"two","source":"three"}""",
66+
screenSnippet,
67+
ScreenSnippet.serializer(),
68+
json
69+
)
70+
}
71+
72+
@Test
73+
fun testPropertiesNotInConstructor() {
74+
assertStringFormAndRestored("""{"b":"val b","a":"val a","c":"val c"}""", NotInConstructorTest(), NotInConstructorTest.serializer())
75+
}
7676
}

integration-test/src/jsTest/kotlin/sample/SampleTestsJS.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ class SampleTestsJS {
88
fun testHello() {
99
assertTrue("JS" in hello())
1010
}
11-
}
11+
}

0 commit comments

Comments
 (0)