K2: don't count use-sites of Java type parameter with nullable bounds as not null
This commit is contained in:
committed by
Space Team
parent
d353fd400d
commit
c4bcdc42c1
+9
@@ -47,6 +47,7 @@ import org.jetbrains.kotlin.fir.utils.exceptions.withFirEntry
|
||||
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType
|
||||
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType.VALUE_PARAMETER
|
||||
import org.jetbrains.kotlin.load.java.FakePureImplementationsProvider
|
||||
import org.jetbrains.kotlin.load.java.JavaDefaultQualifiers
|
||||
import org.jetbrains.kotlin.load.java.JavaTypeQualifiersByElementType
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.load.java.typeEnhancement.*
|
||||
@@ -793,6 +794,14 @@ private class EnhancementSignatureParts(
|
||||
|
||||
override val TypeParameterMarker.isFromJava: Boolean
|
||||
get() = (this as ConeTypeParameterLookupTag).symbol.fir.origin is FirDeclarationOrigin.Java
|
||||
|
||||
override fun getDefaultNullability(
|
||||
referencedParameterBoundsNullability: NullabilityQualifierWithMigrationStatus?,
|
||||
defaultTypeQualifiers: JavaDefaultQualifiers?
|
||||
): NullabilityQualifierWithMigrationStatus? {
|
||||
return referencedParameterBoundsNullability?.takeIf { it.qualifier == NullabilityQualifier.NOT_NULL }
|
||||
?: defaultTypeQualifiers?.nullabilityQualifier
|
||||
}
|
||||
}
|
||||
|
||||
class FirEnhancedSymbolsStorage(private val cachesFactory: FirCachesFactory) : FirSessionComponent {
|
||||
|
||||
+4
-8
@@ -17,19 +17,15 @@ public class Test {}
|
||||
fun <T : Test> main(a1: NonPlatformTypeParameter<Any?>, a2: NonPlatformTypeParameter<Test>, x: T): Unit {
|
||||
a1.foo(null)
|
||||
a1.bar<Test?>(null)
|
||||
// jspecify_nullness_mismatch
|
||||
a1.bar<T>(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a1.bar<T>(null)
|
||||
a1.bar<T>(x)
|
||||
|
||||
// jspecify_nullness_mismatch
|
||||
a2.foo(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a2.foo(null)
|
||||
a2.bar<Test?>(null)
|
||||
// jspecify_nullness_mismatch
|
||||
a2.bar<T>(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a2.bar<T>(null)
|
||||
a2.bar<T>(x)
|
||||
}
|
||||
|
||||
fun testNullable(a1: NonPlatformTypeParameter<Test>, x: Test?) {
|
||||
// jspecify_nullness_mismatch
|
||||
a1.foo(<!ARGUMENT_TYPE_MISMATCH!>x<!>)
|
||||
a1.foo(x)
|
||||
}
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +TypeEnhancementImprovementsInStrictMode
|
||||
// JSPECIFY_STATE: strict
|
||||
// MUTE_FOR_PSI_CLASS_FILES_READING
|
||||
|
||||
// FILE: NonPlatformTypeParameter.java
|
||||
import org.jspecify.nullness.*;
|
||||
|
||||
public class NonPlatformTypeParameter<T extends @Nullable Object> {
|
||||
public void foo(T t) {}
|
||||
public <E extends @Nullable Object> void bar(E e) {}
|
||||
}
|
||||
|
||||
// FILE: Test.java
|
||||
public class Test {}
|
||||
|
||||
// FILE: main.kt
|
||||
fun <T : Test> main(a1: NonPlatformTypeParameter<Any?>, a2: NonPlatformTypeParameter<Test>, x: T): Unit {
|
||||
a1.foo(null)
|
||||
a1.bar<Test?>(null)
|
||||
// jspecify_nullness_mismatch
|
||||
a1.bar<T>(null)
|
||||
a1.bar<T>(x)
|
||||
|
||||
// jspecify_nullness_mismatch
|
||||
a2.foo(null)
|
||||
a2.bar<Test?>(null)
|
||||
// jspecify_nullness_mismatch
|
||||
a2.bar<T>(null)
|
||||
a2.bar<T>(x)
|
||||
}
|
||||
+1
-2
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ProhibitUsingNullableTypeParameterAgainstNotNullAnnotated +TypeEnhancementImprovementsInStrictMode
|
||||
// JSPECIFY_STATE: strict
|
||||
// MUTE_FOR_PSI_CLASS_FILES_READING
|
||||
@@ -28,4 +27,4 @@ fun <T : Test> main(a1: NonPlatformTypeParameter<Any?>, a2: NonPlatformTypeParam
|
||||
// jspecify_nullness_mismatch
|
||||
a2.bar<T>(<!NULL_FOR_NONNULL_TYPE!>null<!>)
|
||||
a2.bar<T>(x)
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
-39
@@ -1,39 +0,0 @@
|
||||
// FULL_JDK
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// LANGUAGE: -SupportJavaErrorEnhancementOfArgumentsOfWarningLevelEnhanced
|
||||
|
||||
// FILE: ElementTypesAreNonnullByDefault.java
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ElementType.TYPE})
|
||||
@TypeQualifierDefault({ElementType.FIELD, ElementType.METHOD, ElementType.PARAMETER})
|
||||
@Nonnull
|
||||
@interface ElementTypesAreNonnullByDefault {
|
||||
}
|
||||
|
||||
// FILE: Maps.java
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
// Here it's important that @ElementTypesAreNonnullByDefault is a JSR-305 default qualifier and disabled by default (resulting in warnings-only)
|
||||
// Thus return type (head type) is considered as warningly-annotated as not-nullable and that makes annotations on bounds for K and V
|
||||
// be effectively ignored on non-warnings level.
|
||||
// Behavior was changed in K2, see KT-63209.
|
||||
@ElementTypesAreNonnullByDefault
|
||||
public final class Maps {
|
||||
public static <K extends @Nullable Object, V extends @Nullable Object> java.util.HashMap<K,V> newHashMap() { return null; }
|
||||
}
|
||||
|
||||
// FILE: main.kt
|
||||
|
||||
fun foo() {
|
||||
val x = Maps.newHashMap<String, Int>()
|
||||
x.put("", 1)
|
||||
// If there were no @ElementTypesAreNonnullByDefault on the Maps class, there would be an error on `null` argument because the type of `x`
|
||||
// would be `HashMap<String, Int>!`, i.e. with non-flexible type arguments, thus not allowing nulls.
|
||||
x.put("", <!NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS!>null<!>)
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// FULL_JDK
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
|
||||
// LANGUAGE: -SupportJavaErrorEnhancementOfArgumentsOfWarningLevelEnhanced
|
||||
|
||||
Vendored
+16
-16
@@ -93,20 +93,20 @@ FILE fqName:<root> fileName:/1.kt
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Java3'
|
||||
<T>: kotlin.Int?
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:D modality:FINAL visibility:public superTypes:[<root>.Java3<kotlin.Int?>]'
|
||||
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int?>) returnType:@[EnhancedNullability] kotlin.Int? [fake_override]
|
||||
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int?>) returnType:@[FlexibleNullability] kotlin.Int? [fake_override]
|
||||
overridden:
|
||||
public open fun bar (): @[EnhancedNullability] T of <root>.Java3 declared in <root>.Java3
|
||||
public open fun bar (): @[FlexibleNullability] T of <root>.Java3? declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Java3<kotlin.Int?>
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int?>, s:@[EnhancedNullability] kotlin.Int?) returnType:kotlin.Unit [fake_override]
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int?>, s:@[FlexibleNullability] kotlin.Int?) returnType:kotlin.Unit [fake_override]
|
||||
overridden:
|
||||
public open fun foo (s: @[EnhancedNullability] T of <root>.Java3): kotlin.Unit declared in <root>.Java3
|
||||
public open fun foo (s: @[FlexibleNullability] T of <root>.Java3?): kotlin.Unit declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Java3<kotlin.Int?>
|
||||
VALUE_PARAMETER name:s index:0 type:@[EnhancedNullability] kotlin.Int?
|
||||
VALUE_PARAMETER name:s index:0 type:@[FlexibleNullability] kotlin.Int?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in <root>.Java3
|
||||
@@ -122,20 +122,20 @@ FILE fqName:<root> fileName:/1.kt
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Java3'
|
||||
<T>: kotlin.Int
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:E modality:FINAL visibility:public superTypes:[<root>.Java3<kotlin.Int>]'
|
||||
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int>) returnType:@[EnhancedNullability] kotlin.Int [fake_override]
|
||||
FUN FAKE_OVERRIDE name:bar visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int>) returnType:@[FlexibleNullability] kotlin.Int? [fake_override]
|
||||
overridden:
|
||||
public open fun bar (): @[EnhancedNullability] T of <root>.Java3 declared in <root>.Java3
|
||||
public open fun bar (): @[FlexibleNullability] T of <root>.Java3? declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Java3<kotlin.Int>
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int>, s:@[EnhancedNullability] kotlin.Int) returnType:kotlin.Unit [fake_override]
|
||||
FUN FAKE_OVERRIDE name:foo visibility:public modality:OPEN <> ($this:<root>.Java3<kotlin.Int>, s:@[FlexibleNullability] kotlin.Int?) returnType:kotlin.Unit [fake_override]
|
||||
overridden:
|
||||
public open fun foo (s: @[EnhancedNullability] T of <root>.Java3): kotlin.Unit declared in <root>.Java3
|
||||
public open fun foo (s: @[FlexibleNullability] T of <root>.Java3?): kotlin.Unit declared in <root>.Java3
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Java3<kotlin.Int>
|
||||
VALUE_PARAMETER name:s index:0 type:@[EnhancedNullability] kotlin.Int
|
||||
VALUE_PARAMETER name:s index:0 type:@[FlexibleNullability] kotlin.Int?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in <root>.Java3
|
||||
@@ -246,23 +246,23 @@ FILE fqName:<root> fileName:/1.kt
|
||||
$this: GET_VAR 'c: <root>.C declared in <root>.test' type=<root>.C origin=null
|
||||
s: CONST Int type=kotlin.Int value=1
|
||||
VAR name:k7 type:kotlin.Int? [val]
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[EnhancedNullability] T of <root>.Java3 visibility:public' type=@[EnhancedNullability] kotlin.Int? origin=null
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] T of <root>.Java3? visibility:public' type=@[FlexibleNullability] kotlin.Int? origin=null
|
||||
receiver: GET_VAR 'd: <root>.D declared in <root>.test' type=<root>.D origin=null
|
||||
VAR name:k8 type:kotlin.Int? [val]
|
||||
CALL 'public open fun bar (): @[EnhancedNullability] kotlin.Int? declared in <root>.D' type=@[EnhancedNullability] kotlin.Int? origin=null
|
||||
CALL 'public open fun bar (): @[FlexibleNullability] kotlin.Int? declared in <root>.D' type=@[FlexibleNullability] kotlin.Int? origin=null
|
||||
$this: GET_VAR 'd: <root>.D declared in <root>.test' type=<root>.D origin=null
|
||||
CALL 'public open fun foo (s: @[EnhancedNullability] kotlin.Int?): kotlin.Unit declared in <root>.D' type=kotlin.Unit origin=null
|
||||
CALL 'public open fun foo (s: @[FlexibleNullability] kotlin.Int?): kotlin.Unit declared in <root>.D' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'd: <root>.D declared in <root>.test' type=<root>.D origin=null
|
||||
s: CONST Null type=kotlin.Nothing? value=null
|
||||
VAR name:k9 type:kotlin.Int [val]
|
||||
TYPE_OP type=kotlin.Int origin=IMPLICIT_NOTNULL typeOperand=kotlin.Int
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[EnhancedNullability] T of <root>.Java3 visibility:public' type=@[EnhancedNullability] kotlin.Int origin=null
|
||||
GET_FIELD 'FIELD IR_EXTERNAL_JAVA_DECLARATION_STUB name:a type:@[FlexibleNullability] T of <root>.Java3? visibility:public' type=@[FlexibleNullability] kotlin.Int? origin=null
|
||||
receiver: GET_VAR 'e: <root>.E declared in <root>.test' type=<root>.E origin=null
|
||||
VAR name:k10 type:kotlin.Int [val]
|
||||
TYPE_OP type=kotlin.Int origin=IMPLICIT_NOTNULL typeOperand=kotlin.Int
|
||||
CALL 'public open fun bar (): @[EnhancedNullability] kotlin.Int declared in <root>.E' type=@[EnhancedNullability] kotlin.Int origin=null
|
||||
CALL 'public open fun bar (): @[FlexibleNullability] kotlin.Int? declared in <root>.E' type=@[FlexibleNullability] kotlin.Int? origin=null
|
||||
$this: GET_VAR 'e: <root>.E declared in <root>.test' type=<root>.E origin=null
|
||||
CALL 'public open fun foo (s: @[EnhancedNullability] kotlin.Int): kotlin.Unit declared in <root>.E' type=kotlin.Unit origin=null
|
||||
CALL 'public open fun foo (s: @[FlexibleNullability] kotlin.Int?): kotlin.Unit declared in <root>.E' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'e: <root>.E declared in <root>.test' type=<root>.E origin=null
|
||||
s: CONST Int type=kotlin.Int value=1
|
||||
VAR name:k11 type:kotlin.Int [val]
|
||||
|
||||
compiler/testData/ir/irText/fakeOverrides/annotations/typeParameterAnnotationOverride.fir.sig.kt.txt
Vendored
+173
@@ -0,0 +1,173 @@
|
||||
// CHECK:
|
||||
// Mangled name: A
|
||||
// Public signature: /A|null[0]
|
||||
class A : Java1<Int> {
|
||||
// CHECK:
|
||||
// Mangled name: A#<init>(){}
|
||||
// Public signature: /A.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: A#bar(){}kotlin.Int{EnhancedNullability}
|
||||
// Public signature: /A.bar|-8608075298013083950[0]
|
||||
// Public signature debug description: bar(){}kotlin.Int{EnhancedNullability}
|
||||
/* fake */ override fun bar(): @EnhancedNullability Int
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: A#foo(kotlin.Int{EnhancedNullability}){}
|
||||
// Public signature: /A.foo|6054053236451526699[0]
|
||||
// Public signature debug description: foo(kotlin.Int{EnhancedNullability}){}
|
||||
/* fake */ override fun foo(s: @EnhancedNullability Int): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: B
|
||||
// Public signature: /B|null[0]
|
||||
class B<T : Any> : Java1<T> {
|
||||
// CHECK:
|
||||
// Mangled name: B#<init>(){}
|
||||
// Public signature: /B.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: B#bar(){}1:0{EnhancedNullability}
|
||||
// Public signature: /B.bar|582597716914558172[0]
|
||||
// Public signature debug description: bar(){}1:0{EnhancedNullability}
|
||||
/* fake */ override fun bar(): @EnhancedNullability T
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: B#foo(1:0{EnhancedNullability}){}
|
||||
// Public signature: /B.foo|-5059967198211209740[0]
|
||||
// Public signature debug description: foo(1:0{EnhancedNullability}){}
|
||||
/* fake */ override fun foo(s: @EnhancedNullability T): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: C
|
||||
// Public signature: /C|null[0]
|
||||
class C : Java2 {
|
||||
// CHECK:
|
||||
// Mangled name: C#<init>(){}
|
||||
// Public signature: /C.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: C#bar(){}kotlin.Int{EnhancedNullability}
|
||||
// Public signature: /C.bar|-8608075298013083950[0]
|
||||
// Public signature debug description: bar(){}kotlin.Int{EnhancedNullability}
|
||||
/* fake */ override fun bar(): @EnhancedNullability Int
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: C#foo(kotlin.Int{EnhancedNullability}){}
|
||||
// Public signature: /C.foo|6054053236451526699[0]
|
||||
// Public signature debug description: foo(kotlin.Int{EnhancedNullability}){}
|
||||
/* fake */ override fun foo(s: @EnhancedNullability Int): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: D
|
||||
// Public signature: /D|null[0]
|
||||
class D : Java3<Int?> {
|
||||
// CHECK:
|
||||
// Mangled name: D#<init>(){}
|
||||
// Public signature: /D.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: D#bar(){}kotlin.Int?
|
||||
// Public signature: /D.bar|793910862689138186[0]
|
||||
// Public signature debug description: bar(){}kotlin.Int?
|
||||
/* fake */ override fun bar(): Int?
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: D#foo(kotlin.Int?){}
|
||||
// Public signature: /D.foo|-4109638554625433529[0]
|
||||
// Public signature debug description: foo(kotlin.Int?){}
|
||||
/* fake */ override fun foo(s: Int?): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: E
|
||||
// Public signature: /E|null[0]
|
||||
class E : Java3<Int> {
|
||||
// CHECK:
|
||||
// Mangled name: E#<init>(){}
|
||||
// Public signature: /E.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: E#bar(){}kotlin.Int?
|
||||
// Public signature: /E.bar|793910862689138186[0]
|
||||
// Public signature debug description: bar(){}kotlin.Int?
|
||||
/* fake */ override fun bar(): Int?
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: E#foo(kotlin.Int?){}
|
||||
// Public signature: /E.foo|-4109638554625433529[0]
|
||||
// Public signature debug description: foo(kotlin.Int?){}
|
||||
/* fake */ override fun foo(s: Int?): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: F
|
||||
// Public signature: /F|null[0]
|
||||
class F : Java4<Int> {
|
||||
// CHECK:
|
||||
// Mangled name: F#<init>(){}
|
||||
// Public signature: /F.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: F#bar(){}kotlin.Int{EnhancedNullability}
|
||||
// Public signature: /F.bar|-8608075298013083950[0]
|
||||
// Public signature debug description: bar(){}kotlin.Int{EnhancedNullability}
|
||||
/* fake */ override fun bar(): @EnhancedNullability Int
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: F#foo(kotlin.Int{EnhancedNullability}){}
|
||||
// Public signature: /F.foo|6054053236451526699[0]
|
||||
// Public signature debug description: foo(kotlin.Int{EnhancedNullability}){}
|
||||
/* fake */ override fun foo(s: @EnhancedNullability Int): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: G
|
||||
// Public signature: /G|null[0]
|
||||
class G<T : Number> : Java4<T> {
|
||||
// CHECK:
|
||||
// Mangled name: G#<init>(){}
|
||||
// Public signature: /G.<init>|-5645683436151566731[0]
|
||||
// Public signature debug description: <init>(){}
|
||||
constructor() /* primary */
|
||||
|
||||
// CHECK JVM_IR:
|
||||
// Mangled name: G#bar(){}1:0{EnhancedNullability}
|
||||
// Public signature: /G.bar|582597716914558172[0]
|
||||
// Public signature debug description: bar(){}1:0{EnhancedNullability}
|
||||
/* fake */ override fun bar(): @EnhancedNullability T
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: G#foo(1:0{EnhancedNullability}){}
|
||||
// Public signature: /G.foo|-5059967198211209740[0]
|
||||
// Public signature debug description: foo(1:0{EnhancedNullability}){}
|
||||
/* fake */ override fun foo(s: @EnhancedNullability T): Unit
|
||||
|
||||
}
|
||||
|
||||
// CHECK:
|
||||
// Mangled name: #test(A;B<kotlin.String>;C;D;E;F;G<kotlin.Int>){}
|
||||
// Public signature: /test|-5249852593213170382[0]
|
||||
// Public signature debug description: test(A;B<kotlin.String>;C;D;E;F;G<kotlin.Int>){}
|
||||
fun test(a: A, b: B<String>, c: C, d: D, e: E, f: F, g: G<Int>): Unit
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
// TARGET_BACKEND: JVM
|
||||
// SEPARATE_SIGNATURE_DUMP_FOR_K2
|
||||
|
||||
// FILE: Java1.java
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
FILE fqName:<root> fileName:/test.kt
|
||||
CLASS CLASS name:Inv modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Inv<T of <root>.Inv>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Inv visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'x: T of <root>.Inv declared in <root>.Inv.<init>' type=T of <root>.Inv origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.Inv<T of <root>.Inv>) returnType:T of <root>.Inv
|
||||
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Inv<T of <root>.Inv>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-x> (): T of <root>.Inv declared in <root>.Inv'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:T of <root>.Inv visibility:private [final]' type=T of <root>.Inv origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Inv<T of <root>.Inv> declared in <root>.Inv.<get-x>' type=<root>.Inv<T of <root>.Inv> origin=null
|
||||
CONSTRUCTOR visibility:public <> (x:T of <root>.Inv) returnType:<root>.Inv<T of <root>.Inv> [primary]
|
||||
VALUE_PARAMETER name:x index:0 type:T of <root>.Inv
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Inv modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in kotlin.Any
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CLASS CLASS name:Test_1 modality:FINAL visibility:public superTypes:[<root>.JavaClass1<TT of <root>.Test_1>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test_1<TT of <root>.Test_1>
|
||||
TYPE_PARAMETER name:TT index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
FIELD PROPERTY_BACKING_FIELD name:x type:TT of <root>.Test_1 visibility:private [final]
|
||||
EXPRESSION_BODY
|
||||
GET_VAR 'x: TT of <root>.Test_1 declared in <root>.Test_1.<init>' type=TT of <root>.Test_1 origin=INITIALIZE_PROPERTY_FROM_PARAMETER
|
||||
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:<root>.Test_1<TT of <root>.Test_1>) returnType:TT of <root>.Test_1
|
||||
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Test_1<TT of <root>.Test_1>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-x> (): TT of <root>.Test_1 declared in <root>.Test_1'
|
||||
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:TT of <root>.Test_1 visibility:private [final]' type=TT of <root>.Test_1 origin=null
|
||||
receiver: GET_VAR '<this>: <root>.Test_1<TT of <root>.Test_1> declared in <root>.Test_1.<get-x>' type=<root>.Test_1<TT of <root>.Test_1> origin=null
|
||||
CONSTRUCTOR visibility:public <> (x:TT of <root>.Test_1) returnType:<root>.Test_1<TT of <root>.Test_1> [primary]
|
||||
VALUE_PARAMETER name:x index:0 type:TT of <root>.Test_1
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.JavaClass1'
|
||||
<T>: TT of <root>.Test_1
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test_1 modality:FINAL visibility:public superTypes:[<root>.JavaClass1<TT of <root>.Test_1>]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.JavaClass1
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in <root>.JavaClass1
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in <root>.JavaClass1
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN name:test visibility:public modality:FINAL <> ($this:<root>.Test_1<TT of <root>.Test_1>, b:<root>.JavaClass1.B<TT of <root>.Test_1>) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Test_1<TT of <root>.Test_1>
|
||||
VALUE_PARAMETER name:b index:0 type:<root>.JavaClass1.B<TT of <root>.Test_1>
|
||||
BLOCK_BODY
|
||||
CALL 'public open fun output (x: @[FlexibleNullability] T of <root>.JavaClass1?): kotlin.Unit declared in <root>.JavaClass1.B' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'b: <root>.JavaClass1.B<TT of <root>.Test_1> declared in <root>.Test_1.test' type=<root>.JavaClass1.B<TT of <root>.Test_1> origin=null
|
||||
x: CALL 'public final fun <get-x> (): TT of <root>.Test_1 declared in <root>.Test_1' type=TT of <root>.Test_1 origin=GET_PROPERTY
|
||||
$this: GET_VAR '<this>: <root>.Test_1<TT of <root>.Test_1> declared in <root>.Test_1.test' type=<root>.Test_1<TT of <root>.Test_1> origin=null
|
||||
CLASS CLASS name:Test_2 modality:FINAL visibility:public superTypes:[<root>.JavaClass2<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Test_2<TT of <root>.Test_2>
|
||||
TYPE_PARAMETER name:TT index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Test_2<TT of <root>.Test_2> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.JavaClass2'
|
||||
<T>: TT of <root>.Test_2
|
||||
<R>: <root>.Inv<TT of <root>.Test_2>
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Test_2 modality:FINAL visibility:public superTypes:[<root>.JavaClass2<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>>]'
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
overridden:
|
||||
public open fun equals (other: kotlin.Any?): kotlin.Boolean declared in <root>.JavaClass2
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
VALUE_PARAMETER name:other index:0 type:kotlin.Any?
|
||||
FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override]
|
||||
overridden:
|
||||
public open fun hashCode (): kotlin.Int declared in <root>.JavaClass2
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override]
|
||||
overridden:
|
||||
public open fun toString (): kotlin.String declared in <root>.JavaClass2
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN name:process visibility:public modality:FINAL <> ($this:<root>.Test_2<TT of <root>.Test_2>, b:<root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>>) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Test_2<TT of <root>.Test_2>
|
||||
VALUE_PARAMETER name:b index:0 type:<root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>>
|
||||
BLOCK_BODY
|
||||
CALL 'public abstract fun output (output: @[FlexibleNullability] R of <root>.JavaClass2?): kotlin.Unit declared in <root>.JavaClass2.B' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'b: <root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>> declared in <root>.Test_2.process' type=<root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>> origin=null
|
||||
output: CONSTRUCTOR_CALL 'public constructor <init> (x: T of <root>.Inv) declared in <root>.Inv' type=<root>.Inv<TT of <root>.Test_2> origin=null
|
||||
<class: T>: TT of <root>.Test_2
|
||||
x: CALL 'public abstract fun element (): @[FlexibleNullability] T of <root>.JavaClass2? declared in <root>.JavaClass2.B' type=@[FlexibleNullability] TT of <root>.Test_2? origin=null
|
||||
$this: GET_VAR 'b: <root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>> declared in <root>.Test_2.process' type=<root>.JavaClass2.B<TT of <root>.Test_2, <root>.Inv<TT of <root>.Test_2>> origin=null
|
||||
FUN name:test_3 visibility:public modality:FINAL <R> (jb:<root>.JavaClass1.B<R of <root>.test_3>, r:R of <root>.test_3) returnType:kotlin.Unit
|
||||
TYPE_PARAMETER name:R index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
VALUE_PARAMETER name:jb index:0 type:<root>.JavaClass1.B<R of <root>.test_3>
|
||||
VALUE_PARAMETER name:r index:1 type:R of <root>.test_3
|
||||
BLOCK_BODY
|
||||
CALL 'public open fun output (x: @[FlexibleNullability] T of <root>.JavaClass1?): kotlin.Unit declared in <root>.JavaClass1.B' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR 'jb: <root>.JavaClass1.B<R of <root>.test_3> declared in <root>.test_3' type=<root>.JavaClass1.B<R of <root>.test_3> origin=null
|
||||
x: GET_VAR 'r: R of <root>.test_3 declared in <root>.test_3' type=R of <root>.test_3 origin=null
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
class Inv<T : Any?> {
|
||||
val x: T
|
||||
field = x
|
||||
get
|
||||
|
||||
constructor(x: T) /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test_1<TT : Any?> : JavaClass1<TT> {
|
||||
val x: TT
|
||||
field = x
|
||||
get
|
||||
|
||||
constructor(x: TT) /* primary */ {
|
||||
super/*JavaClass1*/<TT>()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
fun test(b: B<TT>) {
|
||||
b.output(x = <this>.<get-x>())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Test_2<TT : Any?> : JavaClass2<TT, Inv<TT>> {
|
||||
constructor() /* primary */ {
|
||||
super/*JavaClass2*/<TT, Inv<TT>>()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
fun process(b: B<TT, Inv<TT>>) {
|
||||
b.output(output = Inv<TT>(x = b.element()))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun <R : Any?> test_3(jb: B<R>, r: R) {
|
||||
jb.output(x = r)
|
||||
}
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// FIR_IDENTICAL
|
||||
// TARGET_BACKEND: JVM_IR
|
||||
// ISSUE: KT-57022
|
||||
|
||||
|
||||
+10
-4
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.load.java.typeEnhancement
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.load.java.AbstractAnnotationTypeQualifierResolver
|
||||
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType
|
||||
import org.jetbrains.kotlin.load.java.JavaDefaultQualifiers
|
||||
import org.jetbrains.kotlin.load.java.JavaTypeQualifiersByElementType
|
||||
import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -112,14 +113,14 @@ abstract class AbstractSignatureParts<TAnnotation : Any> {
|
||||
// happens if T is bounded by @NotNull (technically !! is redundant) or context says unannotated
|
||||
// type parameters are non-null;
|
||||
// T - NOT_NULL, isNotNullTypeParameter = false
|
||||
// happens if T is bounded by @Nullable (should it?) or context says unannotated types in general are non-null;
|
||||
// happens if T is bounded by @Nullable (should it? see *) or context says unannotated types in general are non-null;
|
||||
// T? - NULLABLE, isNotNullTypeParameter = false
|
||||
// happens if context says unannotated types in general are nullable.
|
||||
// (*) in this questionable case K1 counts parameter use-sites as not null, and K2 as flexible if has no other context
|
||||
// see getDefaultNullability implementations
|
||||
// For other types, this is more straightforward (just take nullability from the context).
|
||||
// TODO: clean up the representation of those cases in JavaTypeQualifiers
|
||||
val defaultNullability =
|
||||
referencedParameterBoundsNullability?.copy(qualifier = NullabilityQualifier.NOT_NULL)
|
||||
?: defaultTypeQualifier?.nullabilityQualifier
|
||||
val defaultNullability = getDefaultNullability(referencedParameterBoundsNullability, defaultTypeQualifier)
|
||||
val definitelyNotNull =
|
||||
referencedParameterBoundsNullability?.qualifier == NullabilityQualifier.NOT_NULL ||
|
||||
(typeParameterUse != null && defaultTypeQualifier?.definitelyNotNull == true)
|
||||
@@ -132,6 +133,11 @@ abstract class AbstractSignatureParts<TAnnotation : Any> {
|
||||
return JavaTypeQualifiers(result?.qualifier, annotationsMutability, definitelyNotNull, result?.isForWarningOnly == true)
|
||||
}
|
||||
|
||||
protected abstract fun getDefaultNullability(
|
||||
referencedParameterBoundsNullability: NullabilityQualifierWithMigrationStatus?,
|
||||
defaultTypeQualifiers: JavaDefaultQualifiers?
|
||||
): NullabilityQualifierWithMigrationStatus?
|
||||
|
||||
private fun mostSpecific(
|
||||
a: NullabilityQualifierWithMigrationStatus?,
|
||||
b: NullabilityQualifierWithMigrationStatus?
|
||||
|
||||
+8
@@ -278,4 +278,12 @@ private class SignatureParts(
|
||||
|
||||
override val TypeParameterMarker.isFromJava: Boolean
|
||||
get() = this is LazyJavaTypeParameterDescriptor
|
||||
|
||||
override fun getDefaultNullability(
|
||||
referencedParameterBoundsNullability: NullabilityQualifierWithMigrationStatus?,
|
||||
defaultTypeQualifiers: JavaDefaultQualifiers?
|
||||
): NullabilityQualifierWithMigrationStatus? {
|
||||
return referencedParameterBoundsNullability?.copy(qualifier = NullabilityQualifier.NOT_NULL)
|
||||
?: defaultTypeQualifiers?.nullabilityQualifier
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user