FIR2IR: Do not add implicit casts for types with different nullability

For smart casts, elvises, etc., there are no implicit casts in psi2fir
in changed test data
This commit is contained in:
Denis.Zharkov
2021-01-28 16:38:41 +03:00
parent 5c62ee4ba8
commit 1e0d9f4075
46 changed files with 106 additions and 264 deletions
@@ -53,7 +53,7 @@ fun resolveClashesIfAny(container: ComponentContainer, clashResolvers: List<Plat
val <elvis>: Collection<ComponentDescriptor>? = <get-registrationMap>().get(p0 = resolver.<get-applicableTo>()) as? Collection<ComponentDescriptor>
when {
EQEQ(arg0 = <elvis>, arg1 = null) -> continue
else -> <elvis> /*as Collection<ComponentDescriptor> */
else -> <elvis>
}
}
val substituteDescriptor: ClashResolutionDescriptor<out PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out Any?>>>>>> = ClashResolutionDescriptor<PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out PlatformSpecificExtension<out Any?>>>>>>(container = container, resolver = resolver, clashedComponents = clashedComponents.toList<ComponentDescriptor>())
@@ -164,8 +164,7 @@ FILE fqName:<root> fileName:/ClashResolutionDescriptor.kt
then: CONTINUE label=null loop.label=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: TYPE_OP type=kotlin.collections.Collection<<root>.ComponentDescriptor> origin=IMPLICIT_CAST typeOperand=kotlin.collections.Collection<<root>.ComponentDescriptor>
GET_VAR 'val tmp_1: kotlin.collections.Collection<<root>.ComponentDescriptor>? [val] declared in <root>.resolveClashesIfAny' type=kotlin.collections.Collection<<root>.ComponentDescriptor>? origin=null
then: GET_VAR 'val tmp_1: kotlin.collections.Collection<<root>.ComponentDescriptor>? [val] declared in <root>.resolveClashesIfAny' type=kotlin.collections.Collection<<root>.ComponentDescriptor>? origin=null
VAR name:substituteDescriptor type:<root>.ClashResolutionDescriptor<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out kotlin.Any?>>>>>> [val]
CONSTRUCTOR_CALL 'public constructor <init> (container: <root>.ComponentContainer, resolver: <root>.PlatformExtensionsClashResolver<E of <root>.ClashResolutionDescriptor>, clashedComponents: kotlin.collections.List<<root>.ComponentDescriptor>) [primary] declared in <root>.ClashResolutionDescriptor' type=<root>.ClashResolutionDescriptor<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out kotlin.Any?>>>>>> origin=null
<class: E>: <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out <root>.PlatformSpecificExtension<out kotlin.Any?>>>>>
@@ -79,7 +79,7 @@ fun box(): String {
val tmp0_safe_receiver: ImplicitReceiverValue<*>? = stack.get(name = null)
when {
EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null
else -> tmp0_safe_receiver /*as ImplicitReceiverValue<*> */.<get-type>()
else -> tmp0_safe_receiver.<get-type>()
}
})
}
@@ -249,5 +249,4 @@ FILE fqName:<root> fileName:/ImplicitReceiverStack.kt
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun <get-type> (): kotlin.String declared in <root>.ImplicitReceiverValue' type=kotlin.String origin=GET_PROPERTY
$this: TYPE_OP type=<root>.ImplicitReceiverValue<*> origin=IMPLICIT_CAST typeOperand=<root>.ImplicitReceiverValue<*>
GET_VAR 'val tmp_0: <root>.ImplicitReceiverValue<*>? [val] declared in <root>.box' type=<root>.ImplicitReceiverValue<*>? origin=null
$this: GET_VAR 'val tmp_0: <root>.ImplicitReceiverValue<*>? [val] declared in <root>.box' type=<root>.ImplicitReceiverValue<*>? origin=null
@@ -10,7 +10,7 @@ private fun Reader.nextChar(): Char? {
)
when {
EQEQ(arg0 = tmp0_safe_receiver, arg1 = null) -> null
else -> tmp0_safe_receiver /*as Int */.toChar()
else -> tmp0_safe_receiver.toChar()
}
}
}
@@ -18,21 +18,21 @@ private fun Reader.nextChar(): Char? {
fun Reader.consumeRestOfQuotedSequence(sb: StringBuilder, quote: Char) {
var ch: Char? = <this>.nextChar()
while (when {
EQEQ(arg0 = ch, arg1 = null).not() -> EQEQ(arg0 = ch /*as Char */, arg1 = quote).not()
EQEQ(arg0 = ch, arg1 = null).not() -> EQEQ(arg0 = ch, arg1 = quote).not()
else -> false
}) { // BLOCK
when {
EQEQ(arg0 = ch /*as Char */, arg1 = <get-BACKSLASH>()) -> { // BLOCK
EQEQ(arg0 = ch, arg1 = <get-BACKSLASH>()) -> { // BLOCK
val tmp1_safe_receiver: Char? = <this>.nextChar()
when {
EQEQ(arg0 = tmp1_safe_receiver, arg1 = null) -> null
else -> tmp1_safe_receiver /*as Char */.let<Char, StringBuilder?>(block = local fun <anonymous>(it: Char): StringBuilder? {
else -> tmp1_safe_receiver.let<Char, StringBuilder?>(block = local fun <anonymous>(it: Char): StringBuilder? {
return sb.append(p0 = it)
}
)
}
}
else -> sb.append(p0 = ch /*as Char */)
else -> sb.append(p0 = ch)
} /*~> Unit */
ch = <this>.nextChar()
}
@@ -35,8 +35,7 @@ FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun toChar (): kotlin.Char declared in kotlin.Int' type=kotlin.Char origin=null
$this: TYPE_OP type=kotlin.Int origin=IMPLICIT_CAST typeOperand=kotlin.Int
GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
$this: GET_VAR 'val tmp_0: kotlin.Int? [val] declared in <root>.nextChar' type=kotlin.Int? origin=null
FUN name:consumeRestOfQuotedSequence visibility:public modality:FINAL <> ($receiver:java.io.Reader, sb:java.lang.StringBuilder, quote:kotlin.Char) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:java.io.Reader
VALUE_PARAMETER name:sb index:0 type:java.lang.StringBuilder
@@ -54,8 +53,7 @@ FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
arg1: CONST Null type=kotlin.Nothing? value=null
then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ
$this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ
arg0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: GET_VAR 'quote: kotlin.Char declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
@@ -65,8 +63,7 @@ FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
WHEN type=@[FlexibleNullability] java.lang.StringBuilder? origin=IF
BRANCH
if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ
arg0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
arg1: CALL 'private final fun <get-BACKSLASH> (): kotlin.Char declared in <root>' type=kotlin.Char origin=GET_PROPERTY
then: BLOCK type=java.lang.StringBuilder? origin=SAFE_CALL
VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.Char? [val]
@@ -83,8 +80,7 @@ FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
then: CALL 'public final fun let <T, R> (block: kotlin.Function1<T of kotlin.StandardKt.let, R of kotlin.StandardKt.let>): R of kotlin.StandardKt.let [inline] declared in kotlin.StandardKt' type=java.lang.StringBuilder? origin=null
<T>: kotlin.Char
<R>: java.lang.StringBuilder?
$receiver: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
$receiver: GET_VAR 'val tmp_1: kotlin.Char? [val] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
block: FUN_EXPR type=kotlin.Function1<kotlin.Char, java.lang.StringBuilder?> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> (it:kotlin.Char) returnType:java.lang.StringBuilder?
VALUE_PARAMETER name:it index:0 type:kotlin.Char
@@ -97,8 +93,7 @@ FILE fqName:<root> fileName:/coercionToUnitForNestedWhen.kt
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public open fun append (p0: kotlin.Char): java.lang.StringBuilder? declared in java.lang.StringBuilder' type=java.lang.StringBuilder? origin=null
$this: GET_VAR 'sb: java.lang.StringBuilder declared in <root>.consumeRestOfQuotedSequence' type=java.lang.StringBuilder origin=null
p0: TYPE_OP type=kotlin.Char origin=IMPLICIT_CAST typeOperand=kotlin.Char
GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
p0: GET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Char? origin=null
SET_VAR 'var ch: kotlin.Char? [var] declared in <root>.consumeRestOfQuotedSequence' type=kotlin.Unit origin=EQ
CALL 'private final fun nextChar (): kotlin.Char? declared in <root>' type=kotlin.Char? origin=null
$receiver: GET_VAR '<this>: java.io.Reader declared in <root>.consumeRestOfQuotedSequence' type=java.io.Reader origin=null
@@ -23,10 +23,10 @@ class Flaf {
result = Flaf(javaName = javaName)
}
}
<this>.<get-INSTANCES>().set<String, Flaf>(key = javaName, value = result /*as Flaf */)
<this>.<get-INSTANCES>().set<String, Flaf>(key = javaName, value = result)
}
}
return result /*as Flaf */
return result
}
}
@@ -68,11 +68,9 @@ FILE fqName:<root> fileName:/inapplicableCollectionSet.kt
$receiver: CALL 'private final fun <get-INSTANCES> (): kotlin.collections.MutableMap<kotlin.String, <root>.Flaf> declared in <root>.Flaf' type=kotlin.collections.MutableMap<kotlin.String, <root>.Flaf> origin=GET_PROPERTY
$this: GET_VAR '<this>: <root>.Flaf declared in <root>.Flaf.forJavaName' type=<root>.Flaf origin=null
key: GET_VAR 'javaName: kotlin.String declared in <root>.Flaf.forJavaName' type=kotlin.String origin=null
value: TYPE_OP type=<root>.Flaf origin=IMPLICIT_CAST typeOperand=<root>.Flaf
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
value: GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
RETURN type=kotlin.Nothing from='public final fun forJavaName (javaName: kotlin.String): <root>.Flaf declared in <root>.Flaf'
TYPE_OP type=<root>.Flaf origin=IMPLICIT_CAST typeOperand=<root>.Flaf
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
GET_VAR 'var result: <root>.Flaf? [var] declared in <root>.Flaf.forJavaName' type=<root>.Flaf? origin=null
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 [operator] declared in kotlin.Any
@@ -59,8 +59,8 @@ class IdeWizard {
when {
EQEQ(arg0 = value, arg1 = null) -> return Unit
}
reference.<set-t>(<set-?> = SettingType<V>(type = value /*as V */::class) as T)
reference.<set-v>(<set-?> = value /*as V */)
reference.<set-t>(<set-?> = SettingType<V>(type = value::class) as T)
reference.<set-v>(<set-?> = value)
}
override operator fun getValue(thisRef: Any?, property: KProperty<*>): V? {
@@ -169,12 +169,10 @@ FILE fqName:<root> fileName:/readWriteProperty.kt
CONSTRUCTOR_CALL 'public constructor <init> (type: kotlin.reflect.KClass<out V of <root>.SettingType>) [primary] declared in <root>.SettingType' type=<root>.SettingType<V of <root>.IdeWizard.setting> origin=null
<class: V>: V of <root>.IdeWizard.setting
type: GET_CLASS type=kotlin.reflect.KClass<V of <root>.IdeWizard.setting>
TYPE_OP type=V of <root>.IdeWizard.setting origin=IMPLICIT_CAST typeOperand=V of <root>.IdeWizard.setting
GET_VAR 'value: V of <root>.IdeWizard.setting? declared in <root>.IdeWizard.setting.<no name provided>.setValue' type=V of <root>.IdeWizard.setting? origin=null
GET_VAR 'value: V of <root>.IdeWizard.setting? declared in <root>.IdeWizard.setting.<no name provided>.setValue' type=V of <root>.IdeWizard.setting? origin=null
CALL 'public final fun <set-v> (<set-?>: V of <root>.SettingReference): kotlin.Unit declared in <root>.SettingReference' type=kotlin.Unit origin=EQ
$this: GET_VAR 'reference: <root>.SettingReference<V of <root>.IdeWizard.setting, T of <root>.IdeWizard.setting> declared in <root>.IdeWizard.setting' type=<root>.SettingReference<V of <root>.IdeWizard.setting, T of <root>.IdeWizard.setting> origin=null
<set-?>: TYPE_OP type=V of <root>.IdeWizard.setting origin=IMPLICIT_CAST typeOperand=V of <root>.IdeWizard.setting
GET_VAR 'value: V of <root>.IdeWizard.setting? declared in <root>.IdeWizard.setting.<no name provided>.setValue' type=V of <root>.IdeWizard.setting? origin=null
<set-?>: GET_VAR 'value: V of <root>.IdeWizard.setting? declared in <root>.IdeWizard.setting.<no name provided>.setValue' type=V of <root>.IdeWizard.setting? origin=null
FUN name:getValue visibility:public modality:FINAL <> ($this:<root>.IdeWizard.setting.<no name provided><V of <root>.IdeWizard.setting, T of <root>.IdeWizard.setting>, thisRef:kotlin.Any?, property:kotlin.reflect.KProperty<*>) returnType:V of <root>.IdeWizard.setting? [operator]
overridden:
public abstract fun getValue (thisRef: T of kotlin.properties.ReadWriteProperty, property: kotlin.reflect.KProperty<*>): V of kotlin.properties.ReadWriteProperty [operator] declared in kotlin.properties.ReadWriteProperty