-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Correctly support nullability in type arguments for serializer<T>() i…
…ntrinsic. Nullability info should be added to TYPE_OF operation marker. Fixes Kotlin/kotlinx.serialization#2265 (cherry picked from commit ef9074e)
- Loading branch information
1 parent
34efee5
commit ebdbaab
Showing
5 changed files
with
64 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
plugins/kotlinx-serialization/testData/boxIr/intrinsicsNullable.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// TARGET_BACKEND: JVM_IR | ||
|
||
// WITH_STDLIB | ||
|
||
import kotlinx.serialization.* | ||
import kotlinx.serialization.json.* | ||
import kotlinx.serialization.internal.* | ||
import kotlinx.serialization.descriptors.* | ||
import kotlinx.serialization.modules.* | ||
import java.lang.AssertionError | ||
|
||
inline fun <reified T: Any?> listOfNullable(): KSerializer<List<T?>> = serializer<List<T?>>() | ||
inline fun <reified T: Any> listOfNullableWithNonNullBound(): KSerializer<List<T?>> = serializer<List<T?>>() | ||
inline fun <reified T> listOfNullableNoExplicitBound(): KSerializer<List<T?>> = serializer<List<T?>>() | ||
inline fun <reified T> listOfNullableWithCast(): KSerializer<List<Any?>> = serializer<List<T?>>() as KSerializer<List<Any?>> | ||
inline fun <reified T> listOfUnspecifiedNullability(): KSerializer<List<T>> = serializer<List<T>>() | ||
|
||
inline fun <reified T> getSer(module: SerializersModule): KSerializer<T> { | ||
return module.serializer<T>() | ||
} | ||
|
||
fun check(shouldBeNullable: Boolean, descriptor: SerialDescriptor) { | ||
if (shouldBeNullable == descriptor.isNullable) return | ||
if (shouldBeNullable) throw java.lang.AssertionError("Should be nullable, but is not: $descriptor") | ||
throw java.lang.AssertionError("Should not be nullable, but it is: $descriptor") | ||
} | ||
|
||
fun box(): String { | ||
check(false, serializer<String>().descriptor) | ||
check(true, serializer<String?>().descriptor) | ||
|
||
check(false, serializer<List<String>>().descriptor.elementDescriptors.first()) | ||
check(true, serializer<List<String?>>().descriptor.elementDescriptors.first()) | ||
check(true, serializer<List<String>?>().descriptor) | ||
|
||
check(true, listOfNullable<String>().descriptor.elementDescriptors.first()) | ||
check(true, listOfNullableNoExplicitBound<String>().descriptor.elementDescriptors.first()) | ||
check(true, listOfNullableWithNonNullBound<String>().descriptor.elementDescriptors.first()) | ||
check(true, listOfNullableWithCast<String>().descriptor.elementDescriptors.first()) | ||
|
||
check(false, listOfUnspecifiedNullability<String>().descriptor.elementDescriptors.first()) | ||
check(true, listOfUnspecifiedNullability<String?>().descriptor.elementDescriptors.first()) | ||
|
||
val module = EmptySerializersModule() | ||
check(false, getSer<String>(module).descriptor) | ||
check(true, getSer<String?>(module).descriptor) | ||
|
||
return "OK" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,4 +47,4 @@ fun box(): String { | |
getListSer<Box<*>>() | ||
} | ||
return "OK" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...en/org/jetbrains/kotlinx/serialization/runners/SerializationFirBlackBoxTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
...ests-gen/org/jetbrains/kotlinx/serialization/runners/SerializationIrBoxTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.