IR Scripting: allow to specify nullable types for provided props...

but only explicitly. This does not fix a breaking change described in
#KT-52120, because it seems the correct behavior, but it allows
to "workaround" the problem by specifying nullability explicitly.
Also improve handling of nullable bindings in JSR-223.
#KT-49173 fixed
#KT-51213 fixed
This commit is contained in:
Ilya Chernikov
2022-04-22 15:02:18 +02:00
committed by teamcity
parent 4a66cd0c69
commit 49902bb851
8 changed files with 82 additions and 16 deletions
@@ -14,31 +14,37 @@ import kotlin.reflect.KType
*/
class KotlinType private constructor(
val typeName: String,
@Transient val fromClass: KClass<*>? = null
@Transient val fromClass: KClass<*>?,
val isNullable: Boolean
// TODO: copy properties from KType
) : Serializable {
/**
* Constructs KotlinType from fully-qualified [qualifiedTypeName] in a dot-separated form, e.g. "org.acme.Outer.Inner"
*/
constructor(qualifiedTypeName: String) : this(qualifiedTypeName, null)
@JvmOverloads
constructor(qualifiedTypeName: String, isNullable: Boolean = false)
: this(qualifiedTypeName.removeSuffix("?"), null, isNullable = isNullable || qualifiedTypeName.endsWith('?'))
/**
* Constructs KotlinType from reflected [kclass]
*/
constructor(kclass: KClass<*>) : this(kclass.java.name, kclass)
@JvmOverloads
constructor(kclass: KClass<*>, isNullable: Boolean = false) : this(kclass.java.name, kclass, isNullable)
// TODO: implement other approach for non-class types
/**
* Constructs KotlinType from reflected [ktype]
* Constructs KotlinType from reflected [type]
*/
constructor(type: KType) : this(type.classifier as KClass<*>)
constructor(type: KType) : this(type.classifier as KClass<*>, type.isMarkedNullable)
override fun equals(other: Any?): Boolean =
(other as? KotlinType)?.let { typeName == it.typeName } == true
(other as? KotlinType)?.let { typeName == it.typeName && isNullable == it.isNullable } == true
override fun hashCode(): Int = typeName.hashCode()
override fun hashCode(): Int = typeName.hashCode() + 31 * isNullable.hashCode()
fun withNullability(isNullable: Boolean): KotlinType = KotlinType(typeName, fromClass, isNullable)
companion object {
private const val serialVersionUID: Long = 1L
private const val serialVersionUID: Long = 2L
}
}
}