[FIR2IR] Approximate extension receiver type after type argument substitution
Frontend may leak captured types into type arguments, so they should be approximated before using them in fir2ir cast inserter to determine a specific type from smartcast ^KT-62863 Fixed
This commit is contained in:
committed by
Space Team
parent
d2ebaf4e6c
commit
d08567c2c7
@@ -0,0 +1,111 @@
|
||||
FILE fqName:<root> fileName:/smartcastToStarType.kt
|
||||
CLASS INTERFACE name:Base modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Base<T of <root>.Base>
|
||||
TYPE_PARAMETER name:T index:0 variance:out superTypes:[kotlin.Any?] reified:false
|
||||
FUN name:foo visibility:public modality:ABSTRACT <> ($this:<root>.Base<T of <root>.Base>) returnType:T of <root>.Base
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Base<T of <root>.Base>
|
||||
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:Derived modality:FINAL visibility:public superTypes:[<root>.Base<T of <root>.Derived>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Derived<T of <root>.Derived>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Derived<T of <root>.Derived> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Derived modality:FINAL visibility:public superTypes:[<root>.Base<T of <root>.Derived>]'
|
||||
FUN name:foo visibility:public modality:OPEN <> ($this:<root>.Derived<T of <root>.Derived>) returnType:T of <root>.Derived
|
||||
overridden:
|
||||
public abstract fun foo (): T of <root>.Base declared in <root>.Base
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.Derived<T of <root>.Derived>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun foo (): T of <root>.Derived declared in <root>.Derived'
|
||||
TYPE_OP type=T of <root>.Derived origin=CAST typeOperand=T of <root>.Derived
|
||||
CONST String type=kotlin.String value="error"
|
||||
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>.Base
|
||||
$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>.Base
|
||||
$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>.Base
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN name:bar visibility:public modality:FINAL <T> ($receiver:<root>.Derived<T of <root>.bar>) returnType:<root>.Base<T of <root>.bar>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
$receiver: VALUE_PARAMETER name:<this> type:<root>.Derived<T of <root>.bar>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun bar <T> (): <root>.Base<T of <root>.bar> declared in <root>'
|
||||
BLOCK type=<root>.bar.<no name provided><T of <root>.bar> origin=OBJECT_LITERAL
|
||||
CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Base<T of <root>.bar>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.bar.<no name provided><T of <root>.bar>
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.bar.<no name provided><T of <root>.bar> [primary]
|
||||
BLOCK_BODY
|
||||
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () declared in kotlin.Any'
|
||||
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:<no name provided> modality:FINAL visibility:local superTypes:[<root>.Base<T of <root>.bar>]'
|
||||
FUN name:foo visibility:public modality:OPEN <> ($this:<root>.bar.<no name provided><T of <root>.bar>) returnType:T of <root>.bar
|
||||
overridden:
|
||||
public abstract fun foo (): T of <root>.Base declared in <root>.Base
|
||||
$this: VALUE_PARAMETER name:<this> type:<root>.bar.<no name provided><T of <root>.bar>
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public open fun foo (): T of <root>.bar declared in <root>.bar.<no name provided>'
|
||||
TYPE_OP type=T of <root>.bar origin=CAST typeOperand=T of <root>.bar
|
||||
CONST String type=kotlin.String value="OK"
|
||||
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>.Base
|
||||
$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>.Base
|
||||
$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>.Base
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.bar.<no name provided>' type=<root>.bar.<no name provided><T of <root>.bar> origin=OBJECT_LITERAL
|
||||
FUN name:test visibility:public modality:FINAL <T> (x:<root>.Base<T of <root>.test>) returnType:T of <root>.test
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
|
||||
VALUE_PARAMETER name:x index:0 type:<root>.Base<T of <root>.test>
|
||||
BLOCK_BODY
|
||||
WHEN type=kotlin.Unit origin=IF
|
||||
BRANCH
|
||||
if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=<root>.Derived<*>
|
||||
GET_VAR 'x: <root>.Base<T of <root>.test> declared in <root>.test' type=<root>.Base<T of <root>.test> origin=null
|
||||
then: BLOCK type=kotlin.Unit origin=null
|
||||
VAR name:y type:<root>.Base<kotlin.Any?> [val]
|
||||
CALL 'public final fun bar <T> (): <root>.Base<T of <root>.bar> declared in <root>' type=<root>.Base<kotlin.Any?> origin=null
|
||||
<T>: kotlin.Any?
|
||||
$receiver: TYPE_OP type=<root>.Derived<*> origin=IMPLICIT_CAST typeOperand=<root>.Derived<*>
|
||||
GET_VAR 'x: <root>.Base<T of <root>.test> declared in <root>.test' type=<root>.Base<T of <root>.test> origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun test <T> (x: <root>.Base<T of <root>.test>): T of <root>.test declared in <root>'
|
||||
TYPE_OP type=T of <root>.test origin=CAST typeOperand=T of <root>.test
|
||||
CALL 'public abstract fun foo (): T of <root>.Base declared in <root>.Base' type=kotlin.Any? origin=null
|
||||
$this: GET_VAR 'val y: <root>.Base<kotlin.Any?> declared in <root>.test' type=<root>.Base<kotlin.Any?> origin=null
|
||||
RETURN type=kotlin.Nothing from='public final fun test <T> (x: <root>.Base<T of <root>.test>): T of <root>.test declared in <root>'
|
||||
CALL 'public abstract fun foo (): T of <root>.Base declared in <root>.Base' type=T of <root>.test origin=null
|
||||
$this: GET_VAR 'x: <root>.Base<T of <root>.test> declared in <root>.test' type=<root>.Base<T of <root>.test> origin=null
|
||||
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
|
||||
BLOCK_BODY
|
||||
VAR name:x type:<root>.Derived<kotlin.String> [val]
|
||||
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.Derived' type=<root>.Derived<kotlin.String> origin=null
|
||||
<class: T>: kotlin.String
|
||||
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in <root>'
|
||||
CALL 'public final fun test <T> (x: <root>.Base<T of <root>.test>): T of <root>.test declared in <root>' type=kotlin.String origin=null
|
||||
<T>: kotlin.String
|
||||
x: GET_VAR 'val x: <root>.Derived<kotlin.String> declared in <root>.box' type=<root>.Derived<kotlin.String> origin=null
|
||||
@@ -0,0 +1,29 @@
|
||||
// ISSUE: KT-62863
|
||||
// FIR_IDENTICAL
|
||||
// DUMP_IR
|
||||
|
||||
interface Base<out T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
class Derived<T> : Base<T> {
|
||||
override fun foo(): T = "error" as T
|
||||
}
|
||||
|
||||
fun <T> Derived<T>.bar(): Base<T> = object : Base<T> {
|
||||
override fun foo(): T = "OK" as T
|
||||
}
|
||||
|
||||
fun <T> test(x: Base<T>): T {
|
||||
if (x is Derived<*>) {
|
||||
val y: Base<Any?> = x.bar()
|
||||
return y.foo() as T
|
||||
}
|
||||
|
||||
return x.foo()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = Derived<String>()
|
||||
return test(x)
|
||||
}
|
||||
Reference in New Issue
Block a user