[FIR2IR] Properly calculate dispatch receiver type for fake overrides

If some function is not fake-override, then its type should be just
  default type of containing class
For fake overrides the default type calculated in the following way:
1. Find first overridden function, which is not fake override
2. Take its containing class
3. Find supertype of current containing class with type constructor of
   class from step 2

^KT-60252 Fixed
This commit is contained in:
Dmitriy Novozhilov
2023-08-24 14:40:29 +03:00
committed by Space Team
parent e28f97cf6d
commit d4f55894b4
75 changed files with 1866 additions and 2794 deletions
@@ -1,31 +0,0 @@
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 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 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 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 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
@@ -1,11 +0,0 @@
fun interface Foo : Function0<Int> {
}
fun id(foo: Foo): Any {
return foo
}
fun test(foo: Foo) {
id(foo = foo) /*~> Unit */
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// DONT_TARGET_EXACT_BACKEND: JS_IR
fun interface Foo : () -> Int