[FIR] Don't add @EnhancedVisibility to types with @Nullable annotation

This commit is contained in:
Dmitriy Novozhilov
2021-03-12 15:55:46 +03:00
committed by TeamCityServer
parent a7c08345b4
commit 3d1f4b8386
22 changed files with 106 additions and 43 deletions
@@ -0,0 +1,40 @@
// TARGET_BACKEND: JVM
// JVM_TARGET: 1.8
// FILE: Utils.java
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class Utils {
@NotNull
public static A resolveVisibilityFromModifiers(@NotNull A defaultVisibility) {
return A.Companion.getPUBLIC();
}
@Nullable
public static Integer compare(@NotNull A first, @NotNull A second) {
if (first.getIndex() == second.getIndex()) return null;
return Integer.compare(first.getIndex(), second.getIndex());
}
}
// FILE: main.kt
class KtModifierListOwner
class A(val index: Int) {
companion object {
val PUBLIC = A(1)
val PRIVATE = A(2)
}
}
fun test(visibility: A): String {
val parentVisibility = Utils.resolveVisibilityFromModifiers(visibility)
if (Utils.compare(parentVisibility, visibility) ?: 0 < 0) {
return "OK"
}
return "Fail"
}
fun box(): String {
return test(A.PRIVATE)
}
@@ -9,7 +9,7 @@ class Test : J {
<this>.#<$$delegate_0>.takeNotNull(x = x)
}
override fun takeNullable(x: @EnhancedNullability String?) {
override fun takeNullable(x: String?) {
<this>.#<$$delegate_0>.takeNullable(x = x)
}
@@ -23,7 +23,7 @@ class Test : J {
}
@Nullable
override fun returnNullable(): @EnhancedNullability String? {
override fun returnNullable(): String? {
return <this>.#<$$delegate_0>.returnNullable()
}
@@ -16,16 +16,16 @@ FILE fqName:<root> fileName:/delegatedImplementationOfJavaInterface.kt
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.takeNotNull' type=<root>.Test origin=null
x: GET_VAR 'x: @[EnhancedNullability] kotlin.String declared in <root>.Test.takeNotNull' type=@[EnhancedNullability] kotlin.String origin=null
FUN DELEGATED_MEMBER name:takeNullable visibility:public modality:OPEN <> ($this:<root>.Test, x:@[EnhancedNullability] kotlin.String?) returnType:kotlin.Unit
FUN DELEGATED_MEMBER name:takeNullable visibility:public modality:OPEN <> ($this:<root>.Test, x:kotlin.String?) returnType:kotlin.Unit
overridden:
public abstract fun takeNullable (x: @[EnhancedNullability] kotlin.String?): kotlin.Unit declared in <root>.J
public abstract fun takeNullable (x: kotlin.String?): kotlin.Unit declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:<root>.Test
VALUE_PARAMETER name:x index:0 type:@[EnhancedNullability] kotlin.String?
VALUE_PARAMETER name:x index:0 type:kotlin.String?
BLOCK_BODY
CALL 'public abstract fun takeNullable (x: @[EnhancedNullability] kotlin.String?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
CALL 'public abstract fun takeNullable (x: kotlin.String?): kotlin.Unit declared in <root>.J' type=kotlin.Unit origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.takeNullable' type=<root>.Test origin=null
x: GET_VAR 'x: @[EnhancedNullability] kotlin.String? declared in <root>.Test.takeNullable' type=@[EnhancedNullability] kotlin.String? origin=null
x: GET_VAR 'x: kotlin.String? declared in <root>.Test.takeNullable' type=kotlin.String? origin=null
FUN DELEGATED_MEMBER name:takeFlexible visibility:public modality:OPEN <> ($this:<root>.Test, x:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit
overridden:
public abstract fun takeFlexible (x: @[FlexibleNullability] kotlin.String?): kotlin.Unit declared in <root>.J
@@ -47,15 +47,15 @@ FILE fqName:<root> fileName:/delegatedImplementationOfJavaInterface.kt
CALL 'public abstract fun returnNotNull (): @[EnhancedNullability] kotlin.String declared in <root>.J' type=@[EnhancedNullability] kotlin.String origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.returnNotNull' type=<root>.Test origin=null
FUN DELEGATED_MEMBER name:returnNullable visibility:public modality:OPEN <> ($this:<root>.Test) returnType:@[EnhancedNullability] kotlin.String?
FUN DELEGATED_MEMBER name:returnNullable visibility:public modality:OPEN <> ($this:<root>.Test) returnType:kotlin.String?
annotations:
Nullable(value = <null>)
overridden:
public abstract fun returnNullable (): @[EnhancedNullability] kotlin.String? declared in <root>.J
public abstract fun returnNullable (): kotlin.String? declared in <root>.J
$this: VALUE_PARAMETER name:<this> type:<root>.Test
BLOCK_BODY
RETURN type=kotlin.Nothing from='public open fun returnNullable (): @[EnhancedNullability] kotlin.String? declared in <root>.Test'
CALL 'public abstract fun returnNullable (): @[EnhancedNullability] kotlin.String? declared in <root>.J' type=@[EnhancedNullability] kotlin.String? origin=null
RETURN type=kotlin.Nothing from='public open fun returnNullable (): kotlin.String? declared in <root>.Test'
CALL 'public abstract fun returnNullable (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=null
$this: GET_FIELD 'FIELD DELEGATE name:<$$delegate_0> type:<root>.J visibility:local [final]' type=<root>.J origin=null
receiver: GET_VAR '<this>: <root>.Test declared in <root>.Test.returnNullable' type=<root>.Test origin=null
FUN DELEGATED_MEMBER name:returnsFlexible visibility:public modality:OPEN <> ($this:<root>.Test) returnType:@[FlexibleNullability] kotlin.String?
@@ -152,7 +152,7 @@ FILE fqName:<root> fileName:/ClashResolutionDescriptor.kt
BLOCK type=kotlin.collections.Collection<<root>.ComponentDescriptor> origin=ELVIS
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.collections.Collection<<root>.ComponentDescriptor>? [val]
TYPE_OP type=kotlin.collections.Collection<<root>.ComponentDescriptor>? origin=SAFE_CAST typeOperand=kotlin.collections.Collection<<root>.ComponentDescriptor>
CALL 'public open fun get (p0: @[FlexibleNullability] K of java.util.HashMap?): @[EnhancedNullability] V of java.util.HashMap? [operator] declared in java.util.HashMap' type=kotlin.Any? origin=null
CALL 'public open fun get (p0: @[FlexibleNullability] K of java.util.HashMap?): V of java.util.HashMap? [operator] declared in java.util.HashMap' type=kotlin.Any? origin=null
$this: CALL 'private final fun <get-registrationMap> (): java.util.HashMap<java.lang.reflect.Type, kotlin.Any> declared in <root>' type=java.util.HashMap<java.lang.reflect.Type, kotlin.Any> origin=GET_PROPERTY
p0: CALL 'public final fun <get-applicableTo> (): java.lang.Class<E of <root>.PlatformExtensionsClashResolver> declared in <root>.PlatformExtensionsClashResolver' type=java.lang.Class<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out kotlin.Any?>>>>>> origin=GET_PROPERTY
$this: GET_VAR 'val resolver: <root>.PlatformExtensionsClashResolver<*> [val] declared in <root>.resolveClashesIfAny' type=<root>.PlatformExtensionsClashResolver<*> origin=null
+1 -1
View File
@@ -283,7 +283,7 @@ FILE fqName:<root> fileName:/MultiList.kt
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 [fake_override,operator] declared in <root>.MyList
public open fun equals (p0: @[EnhancedNullability] kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in java.util.ArrayList
public open fun equals (p0: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in java.util.ArrayList
$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]
@@ -16,7 +16,7 @@ FILE fqName:<root> fileName:/putIfAbsent.kt
<K>: T of <root>.Owner.foo
<V>: T of <root>.Owner.foo
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public open fun putIfAbsent (p0: @[EnhancedNullability] K of java.util.Map, p1: @[EnhancedNullability] V of java.util.Map): @[EnhancedNullability] V of java.util.Map? declared in java.util.Map' type=T of <root>.Owner.foo? origin=null
CALL 'public open fun putIfAbsent (p0: @[EnhancedNullability] K of java.util.Map, p1: @[EnhancedNullability] V of java.util.Map): V of java.util.Map? declared in java.util.Map' type=T of <root>.Owner.foo? origin=null
$this: GET_VAR 'val map: kotlin.collections.MutableMap<T of <root>.Owner.foo, T of <root>.Owner.foo> [val] declared in <root>.Owner.foo' type=kotlin.collections.MutableMap<T of <root>.Owner.foo, T of <root>.Owner.foo> origin=null
p0: GET_VAR 'x: T of <root>.Owner.foo declared in <root>.Owner.foo' type=T of <root>.Owner.foo origin=null
p1: GET_VAR 'y: T of <root>.Owner.foo declared in <root>.Owner.foo' type=T of <root>.Owner.foo origin=null