blob: 7840cd23621856870e21bfc92dac8e5edcf952bd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
/*
* Copyright 2017-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
*/
package kotlinx.serialization
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.internal.UnitSerializer
import kotlin.test.Test
class SealedGenericClassesTest {
interface Output
@Serializable
data class Something(val s: String) : Output
@Serializable
sealed class Query<T : Output> {
@Serializable
data class SimpleQuery<T: Output>(val rawQuery: String) : Query<T>()
}
@Serializable
sealed class Fetcher<T : Output> {
abstract val query: Query<T>
@Serializable
data class SomethingFetcher(override val query: Query<Something>) : Fetcher<Something>()
}
// Test that compilation and retrieval is successful
@Test
fun testQuery() {
Query.SimpleQuery.serializer(String.serializer())
Query.serializer(UnitSerializer)
}
@Test
fun testFetcher() {
Fetcher.SomethingFetcher.serializer()
Fetcher.serializer(Something.serializer())
}
}
|