Psi2ir: fix function type check for fun interface conversion
Parameter of a synthetic SAM adapter always has a function type (not a subtype). Checking for the subtypes broke the case from KT-46908, where fun interface is itself a subtype of a function type. #KT-46908 Fixed
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
// IGNORE_BACKEND: JS, JS_IR, WASM
|
||||
|
||||
fun interface Foo : () -> Int
|
||||
|
||||
fun id(foo: Foo): Any = foo
|
||||
|
||||
fun box(): String {
|
||||
val p1 = object : Foo {
|
||||
override fun invoke(): Int = 42
|
||||
override fun toString(): String = "OK"
|
||||
}
|
||||
val p2 = id(p1)
|
||||
|
||||
if (p1 !== p2) return "Fail identity equals"
|
||||
if (p1.toString() != p2.toString()) return "Fail toString"
|
||||
|
||||
return p2.toString()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun interface Foo : Function0<Int> {
|
||||
|
||||
}
|
||||
|
||||
fun id(foo: Foo): Any {
|
||||
return foo
|
||||
}
|
||||
|
||||
fun test(foo: Foo) {
|
||||
id(foo = foo) /*~> Unit */
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
FILE fqName:<root> fileName:/functionSupertype.kt
|
||||
CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Function0<kotlin.Int>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo
|
||||
FUN FAKE_OVERRIDE name:invoke visibility:public modality:ABSTRACT <> ($this:kotlin.Function0<R of kotlin.Function0>) returnType:kotlin.Int [fake_override,operator]
|
||||
overridden:
|
||||
public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Function0<R of kotlin.Function0>
|
||||
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 kotlin.Function0
|
||||
$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 [fake_override] declared in kotlin.Function0
|
||||
$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 [fake_override] declared in kotlin.Function0
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN name:id visibility:public modality:FINAL <> (foo:<root>.Foo) returnType:kotlin.Any
|
||||
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun id (foo: <root>.Foo): kotlin.Any declared in <root>'
|
||||
GET_VAR 'foo: <root>.Foo declared in <root>.id' type=<root>.Foo origin=null
|
||||
FUN name:test visibility:public modality:FINAL <> (foo:<root>.Foo) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CALL 'public final fun id (foo: <root>.Foo): kotlin.Any declared in <root>' type=kotlin.Any origin=null
|
||||
foo: GET_VAR 'foo: <root>.Foo declared in <root>.test' type=<root>.Foo origin=null
|
||||
@@ -0,0 +1,9 @@
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
|
||||
fun interface Foo : () -> Int
|
||||
|
||||
fun id(foo: Foo): Any = foo
|
||||
|
||||
fun test(foo: Foo) {
|
||||
id(foo)
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun interface Foo : Function0<Int> {
|
||||
|
||||
}
|
||||
|
||||
fun id(foo: Foo): Any {
|
||||
return foo
|
||||
}
|
||||
|
||||
fun test(foo: Foo) {
|
||||
id(foo = foo) /*~> Unit */
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
FILE fqName:<root> fileName:/functionSupertype.kt
|
||||
CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Function0<kotlin.Int>]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Foo
|
||||
FUN FAKE_OVERRIDE name:invoke visibility:public modality:ABSTRACT <> ($this:kotlin.Function0<kotlin.Int>) returnType:kotlin.Int [fake_override,operator]
|
||||
overridden:
|
||||
public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Function0<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 [fake_override,operator] declared in kotlin.Function0
|
||||
$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 [fake_override] declared in kotlin.Function0
|
||||
$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 [fake_override] declared in kotlin.Function0
|
||||
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
|
||||
FUN name:id visibility:public modality:FINAL <> (foo:<root>.Foo) returnType:kotlin.Any
|
||||
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
RETURN type=kotlin.Nothing from='public final fun id (foo: <root>.Foo): kotlin.Any declared in <root>'
|
||||
GET_VAR 'foo: <root>.Foo declared in <root>.id' type=<root>.Foo origin=null
|
||||
FUN name:test visibility:public modality:FINAL <> (foo:<root>.Foo) returnType:kotlin.Unit
|
||||
VALUE_PARAMETER name:foo index:0 type:<root>.Foo
|
||||
BLOCK_BODY
|
||||
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
|
||||
CALL 'public final fun id (foo: <root>.Foo): kotlin.Any declared in <root>' type=kotlin.Any origin=null
|
||||
foo: GET_VAR 'foo: <root>.Foo declared in <root>.test' type=<root>.Foo origin=null
|
||||
Reference in New Issue
Block a user