Skip to content

Commit

Permalink
Fix deserialization exception for DNN types from Java
Browse files Browse the repository at this point in the history
useCorrectedNullabilityForTypeParameters = true only might lead
to something becomes a DNN when otherwise it wasn't.

It seems safe to use it here, since if compiler has generated DNN, then
it's OK to assume that it checked necessary conditions, and it's likely
that it had useCorrectedNullabilityForTypeParameters = true as well, there.

Anyway, it looks saner than having an exception here.

Also, we assume here that metadata leading to exception might only be generated
with ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated LF
(at least, we don't have contradicting evidences),
thus it's mostly a preparations in case we decide to enable
ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated in 1.9.

^KT-55357 Fixed
^KT-55388 Related
^KT-36770 Related
  • Loading branch information
dzharkov authored and qodana-bot committed Dec 12, 2022
1 parent ea33e72 commit d61cef0
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions compiler/testData/codegen/box/javaInterop/delegationToJavaDnn.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated
// ISSUE: KT-55357

// MODULE: lib
// FILE: J.java
import org.jetbrains.annotations.NotNull;

public interface J {
@NotNull
<T> T foo();
}

// FILE: JImpl.java
public class JImpl implements J {
public <T> T foo() {
return (T) "OK";
}
}
// FILE: a.kt
class C(val x: J) : J by x

// MODULE: main(lib)
// FILE: a.kt

fun box(): String {
return C(JImpl()).foo<String>()
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ class TypeDeserializer(
else ->
KotlinTypeFactory.simpleType(attributes, constructor, arguments, proto.nullable).let {
if (Flags.DEFINITELY_NOT_NULL_TYPE.get(proto.flags))
DefinitelyNotNullType.makeDefinitelyNotNull(it) ?: error("null DefinitelyNotNullType for '$it'")
DefinitelyNotNullType.makeDefinitelyNotNull(it, useCorrectedNullabilityForTypeParameters = true)
?: error("null DefinitelyNotNullType for '$it'")
else
it
}
Expand Down

0 comments on commit d61cef0

Please sign in to comment.