FIR: in case of smart cast, use original type for FirThisRcvrExpression
Before this commit, we used type after smart cast both for original FirThisReceiverExpression and for wrapping FirExpressionWithSmartCast. However, this makes FIR2IR implicit cast generator work incorrectly (it decides not to insert implicit cast because original type is the same). After this commit, expressions have different types and implicit cast generator works properly.
This commit is contained in:
-35
@@ -1,35 +0,0 @@
|
||||
inline fun <reified T : Any> Any.test1(): T? {
|
||||
return when {
|
||||
<this> is T -> <this>
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
interface Foo<T : Any?> {
|
||||
|
||||
}
|
||||
|
||||
val <reified T : Any> Foo<T>.asT: T?
|
||||
inline get(): T? {
|
||||
return when {
|
||||
<this> is T -> <this> /*as T */
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
class Bar<T : Any?> {
|
||||
constructor() /* primary */ {
|
||||
super/*Any*/()
|
||||
/* <init>() */
|
||||
|
||||
}
|
||||
|
||||
fun test(arg: Any) {
|
||||
arg as T /*~> Unit */
|
||||
<this>.useT(t = arg /*as T */)
|
||||
}
|
||||
|
||||
fun useT(t: T) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
FILE fqName:<root> fileName:/implicitCastToTypeParameter.kt
|
||||
FUN name:test1 visibility:public modality:FINAL <T> ($receiver:kotlin.Any) returnType:T of <root>.test1? [inline]
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any]
|
||||
$receiver: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun test1 <T> (): T of <root>.test1? [inline] declared in <root>'
|
||||
WHEN type=T of <root>.test1? origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <root>.test1
|
||||
GET_VAR '<this>: kotlin.Any declared in <root>.test1' type=kotlin.Any origin=null
|
||||
then: GET_VAR '<this>: kotlin.Any declared in <root>.test1' type=T of <root>.test1 origin=null
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: CONST Null type=kotlin.Nothing? value=null
|
||||
CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo<T of <root>.Foo>
|
||||
TYPE_PARAMETER name:T index:0 variance: 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 [operator] 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
|
||||
PROPERTY name:asT visibility:public modality:FINAL [val]
|
||||
FUN name:<get-asT> visibility:public modality:FINAL <T> ($receiver:<root>.Foo<T of <root>.<get-asT>>) returnType:T of <root>.<get-asT>? [inline]
|
||||
correspondingProperty: PROPERTY name:asT visibility:public modality:FINAL [val]
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any]
|
||||
$receiver: VALUE_PARAMETER name:<this> type:<root>.Foo<T of <root>.<get-asT>>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun <get-asT> <T> (): T of <root>.<get-asT>? [inline] declared in <root>'
|
||||
WHEN type=T of <root>.<get-asT>? origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=T of <root>.<get-asT>
|
||||
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
|
||||
then: TYPE_OP type=T of <root>.<get-asT> origin=IMPLICIT_CAST typeOperand=T of <root>.<get-asT>
|
||||
GET_VAR '<this>: <root>.Foo<T of <root>.<get-asT>> declared in <root>.<get-asT>' type=<root>.Foo<T of <root>.<get-asT>> origin=null
|
||||
BRANCH
|
||||
if: CONST Boolean type=kotlin.Boolean value=true
|
||||
then: CONST Null type=kotlin.Nothing? value=null
|
||||
CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Bar<T of <root>.Bar>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Bar<T of <root>.Bar> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Bar modality:FINAL visibility:public superTypes:[kotlin.Any]'
|
||||
FUN name:test visibility:public modality:FINAL <> ($this:<root>.Bar<T of <root>.Bar>, arg:kotlin.Any) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Bar<T of <root>.Bar>
|
||||
VALUE_PARAMETER name:arg index:0 type:kotlin.Any
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
TYPE_OP type=T of <root>.Bar origin=CAST typeOperand=T of <root>.Bar
|
||||
GET_VAR 'arg: kotlin.Any declared in <root>.Bar.test' type=kotlin.Any origin=null
|
||||
CALL 'public final fun useT (t: T of <root>.Bar): kotlin.Unit declared in <root>.Bar' type=kotlin.Unit origin=null
|
||||
$this: GET_VAR '<this>: <root>.Bar<T of <root>.Bar> declared in <root>.Bar.test' type=<root>.Bar<T of <root>.Bar> origin=null
|
||||
t: TYPE_OP type=T of <root>.Bar origin=IMPLICIT_CAST typeOperand=T of <root>.Bar
|
||||
GET_VAR 'arg: kotlin.Any declared in <root>.Bar.test' type=kotlin.Any origin=null
|
||||
FUN name:useT visibility:public modality:FINAL <> ($this:<root>.Bar<T of <root>.Bar>, t:T of <root>.Bar) returnType:kotlin.Unit
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Bar<T of <root>.Bar>
|
||||
VALUE_PARAMETER name:t index:0 type:T of <root>.Bar
|
||||
BLOCK_BODY
|
||||
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
|
||||
$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
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
inline fun <reified T : Any> Any.test1(): T? =
|
||||
if (this is T) this else null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user