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
@@ -20,10 +20,10 @@ fun configureProvidedPropertiesFromJsr223Context(context: ScriptConfigurationRef
}
for ((k, v) in allBindings) {
// only adding bindings that are not already defined and also skip local classes
if (!updatedProperties.containsKey(k) && v::class.qualifiedName != null) {
if (!updatedProperties.containsKey(k) && (v == null || v::class.qualifiedName != null)) {
// TODO: add only valid names
// TODO: find out how it's implemented in other jsr223 engines for typed languages, since this approach prevent certain usage scenarios, e.g. assigning back value of a "sibling" type
updatedProperties[k] = KotlinType(v::class)
updatedProperties[k] = if (v == null) KotlinType(Any::class, isNullable = true) else KotlinType(v::class)
}
}
ScriptCompilationConfiguration(context.compilationConfiguration) {