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:
+3
-2
@@ -13,6 +13,7 @@ import org.jetbrains.kotlin.psi.KtScript
|
||||
import kotlin.reflect.KClass
|
||||
import kotlin.reflect.KType
|
||||
import kotlin.reflect.full.starProjectedType
|
||||
import kotlin.reflect.full.withNullability
|
||||
import kotlin.script.experimental.api.*
|
||||
import kotlin.script.experimental.dependencies.DependenciesResolver
|
||||
import kotlin.script.experimental.host.ScriptingHostConfiguration
|
||||
@@ -68,12 +69,12 @@ abstract class KotlinScriptDefinitionAdapterFromNewAPIBase : KotlinScriptDefinit
|
||||
override val implicitReceivers: List<KType> by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
scriptCompilationConfiguration[ScriptCompilationConfiguration.implicitReceivers]
|
||||
.orEmpty()
|
||||
.map { getScriptingClass(it).starProjectedType }
|
||||
.map { getScriptingClass(it).starProjectedType.withNullability(it.isNullable) }
|
||||
}
|
||||
|
||||
override val providedProperties: List<Pair<String, KType>> by lazy(LazyThreadSafetyMode.PUBLICATION) {
|
||||
scriptCompilationConfiguration[ScriptCompilationConfiguration.providedProperties]
|
||||
?.map { (k, v) -> k to getScriptingClass(v).starProjectedType }.orEmpty()
|
||||
?.map { (k, v) -> k to getScriptingClass(v).starProjectedType.withNullability(v.isNullable) }.orEmpty()
|
||||
}
|
||||
|
||||
@Deprecated("temporary workaround for missing functionality, will be replaced by the new API soon")
|
||||
|
||||
+1
-1
@@ -274,7 +274,7 @@ class LazyScriptDescriptor(
|
||||
scriptCompilationConfiguration()[ScriptCompilationConfiguration.providedProperties].orEmpty()
|
||||
.mapNotNull { (name, type) ->
|
||||
findTypeDescriptor(getScriptingClass(type), Errors.MISSING_SCRIPT_PROVIDED_PROPERTY_CLASS)
|
||||
?.let { name.toValidJvmIdentifier() to it }
|
||||
?.let { name.toValidJvmIdentifier() to it.defaultType.makeNullableAsSpecified(type.isNullable) }
|
||||
}.map { (name, classDescriptor) ->
|
||||
ScriptProvidedPropertyDescriptor(
|
||||
Name.identifier(name),
|
||||
|
||||
+3
-2
@@ -9,10 +9,11 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
class ScriptProvidedPropertyDescriptor(
|
||||
name: Name,
|
||||
typeDescriptor: ClassDescriptor,
|
||||
type: KotlinType,
|
||||
receiver: ReceiverParameterDescriptor?,
|
||||
isVar: Boolean,
|
||||
script: ScriptDescriptor
|
||||
@@ -30,7 +31,7 @@ class ScriptProvidedPropertyDescriptor(
|
||||
/* isDelegated = */ false
|
||||
) {
|
||||
init {
|
||||
setType(typeDescriptor.defaultType, emptyList(), receiver, null, emptyList())
|
||||
setType(type, emptyList(), receiver, null, emptyList())
|
||||
// TODO: consider delegation instead
|
||||
initialize(null, null, null, null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user