PSI2IR KT-44414 fix adapted reference to imported object member

This commit is contained in:
Dmitry Petrov
2021-03-15 18:57:52 +03:00
committed by TeamCityServer
parent e7129329d2
commit d74168fb8f
16 changed files with 235 additions and 14 deletions
@@ -0,0 +1,13 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: BINDING_RECEIVERS
// IGNORE_BACKEND_FIR: JVM_IR
import Host.foo
fun withO(fn: (String) -> String) = fn("O")
object Host {
fun foo(vararg x: String) = x[0] + "K"
}
fun box() = withO(::foo)
@@ -0,0 +1,64 @@
FILE fqName:<root> fileName:/varargFunImportedFromObject.kt
FUN name:withO visibility:public modality:FINAL <> (fn:kotlin.Function1<kotlin.String, kotlin.String>) returnType:kotlin.String
VALUE_PARAMETER name:fn index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>'
CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE
$this: GET_VAR 'fn: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.withO' type=kotlin.Function1<kotlin.String, kotlin.String> origin=VARIABLE_AS_FUNCTION
p1: CONST String type=kotlin.String value="O"
CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host
CONSTRUCTOR visibility:private <> () returnType:<root>.Host [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Host, x:kotlin.Array<out kotlin.String>) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Host
VALUE_PARAMETER name:x index:0 type:kotlin.Array<out kotlin.String> varargElementType:kotlin.String [vararg]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host'
CONST String type=kotlin.String value="K"
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
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.String declared in <root>'
CALL 'public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>' type=kotlin.String origin=null
fn: BLOCK type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:<root>.Host, p0:kotlin.String) returnType:kotlin.String
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:<root>.Host
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test1'
CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR 'receiver: <root>.Host declared in <root>.test1.foo' type=<root>.Host origin=ADAPTED_FUNCTION_REFERENCE
x: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
GET_VAR 'p0: kotlin.String declared in <root>.test1.foo' type=kotlin.String origin=null
FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.String declared in <root>'
CALL 'public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>' type=kotlin.String origin=null
fn: BLOCK type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:<root>.Host, p0:kotlin.String) returnType:kotlin.String
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:<root>.Host
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test2'
CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR 'receiver: <root>.Host declared in <root>.test2.foo' type=<root>.Host origin=ADAPTED_FUNCTION_REFERENCE
x: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
GET_VAR 'p0: kotlin.String declared in <root>.test2.foo' type=kotlin.String origin=null
FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test2' type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=null
$receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
@@ -0,0 +1,11 @@
// SKIP_KT_DUMP
import Host.foo
fun withO(fn: (String) -> String) = fn("O")
object Host {
fun foo(vararg x: String) = "K"
}
fun test1() = withO(::foo)
fun test2() = withO(Host::foo)
@@ -0,0 +1,65 @@
FILE fqName:<root> fileName:/varargFunImportedFromObject.kt
FUN name:withO visibility:public modality:FINAL <> (fn:kotlin.Function1<kotlin.String, kotlin.String>) returnType:kotlin.String
VALUE_PARAMETER name:fn index:0 type:kotlin.Function1<kotlin.String, kotlin.String>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>'
CALL 'public abstract fun invoke (p1: P1 of kotlin.Function1): R of kotlin.Function1 [operator] declared in kotlin.Function1' type=kotlin.String origin=INVOKE
$this: GET_VAR 'fn: kotlin.Function1<kotlin.String, kotlin.String> declared in <root>.withO' type=kotlin.Function1<kotlin.String, kotlin.String> origin=VARIABLE_AS_FUNCTION
p1: CONST String type=kotlin.String value="O"
CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Host
CONSTRUCTOR visibility:private <> () returnType:<root>.Host [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]'
FUN name:foo visibility:public modality:FINAL <> ($this:<root>.Host, x:kotlin.Array<out kotlin.String>) returnType:kotlin.String
$this: VALUE_PARAMETER name:<this> type:<root>.Host
VALUE_PARAMETER name:x index:0 type:kotlin.Array<out kotlin.String> varargElementType:kotlin.String [vararg]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host'
CONST String type=kotlin.String value="K"
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
FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): kotlin.String declared in <root>'
CALL 'public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>' type=kotlin.String origin=null
fn: BLOCK type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:<root>.Host, p0:kotlin.String) returnType:kotlin.String
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:<root>.Host
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test1'
CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR 'receiver: <root>.Host declared in <root>.test1.foo' type=<root>.Host origin=ADAPTED_FUNCTION_REFERENCE
x: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
GET_VAR 'p0: kotlin.String declared in <root>.test1.foo' type=kotlin.String origin=null
FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test1' type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host
$receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
FUN name:test2 visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): kotlin.String declared in <root>'
CALL 'public final fun withO (fn: kotlin.Function1<kotlin.String, kotlin.String>): kotlin.String declared in <root>' type=kotlin.String origin=null
fn: BLOCK type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:foo visibility:local modality:FINAL <> ($receiver:<root>.Host, p0:kotlin.String) returnType:kotlin.String
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:<root>.Host
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.String
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test2'
CALL 'public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR 'receiver: <root>.Host declared in <root>.test2.foo' type=<root>.Host origin=ADAPTED_FUNCTION_REFERENCE
x: VARARG type=kotlin.Array<out kotlin.String> varargElementType=kotlin.String
GET_VAR 'p0: kotlin.String declared in <root>.test2.foo' type=kotlin.String origin=null
FUNCTION_REFERENCE 'local final fun foo (p0: kotlin.String): kotlin.String declared in <root>.test2' type=kotlin.Function1<kotlin.String, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun foo (vararg x: kotlin.String): kotlin.String declared in <root>.Host
$receiver: GET_OBJECT 'CLASS OBJECT name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' type=<root>.Host
@@ -66,8 +66,8 @@ fun testCoercionToUnit() {
fun testImportedObjectMember(): String {
return use(fn = { // BLOCK
local fun importedObjectMemberWithVarargs(p0: Int): String {
return importedObjectMemberWithVarargs(xs = [p0])
local fun Host.importedObjectMemberWithVarargs(p0: Int): String {
return receiver.importedObjectMemberWithVarargs(xs = [p0])
}
Host::importedObjectMemberWithVarargs
@@ -105,11 +105,13 @@ FILE fqName:<root> fileName:/withAdaptedArguments.kt
RETURN type=kotlin.Nothing from='public final fun testImportedObjectMember (): kotlin.String declared in <root>'
CALL 'public final fun use (fn: kotlin.Function1<kotlin.Int, kotlin.String>): kotlin.String declared in <root>' type=kotlin.String origin=null
fn: BLOCK type=kotlin.Function1<kotlin.Int, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:importedObjectMemberWithVarargs visibility:local modality:FINAL <> (p0:kotlin.Int) returnType:kotlin.String
FUN ADAPTER_FOR_CALLABLE_REFERENCE name:importedObjectMemberWithVarargs visibility:local modality:FINAL <> ($receiver:<root>.Host, p0:kotlin.Int) returnType:kotlin.String
$receiver: VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:receiver type:<root>.Host
VALUE_PARAMETER ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE name:p0 index:0 type:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='local final fun importedObjectMemberWithVarargs (p0: kotlin.Int): kotlin.String declared in <root>.testImportedObjectMember'
CALL 'public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in <root>.Host' type=kotlin.String origin=null
$this: GET_VAR 'receiver: <root>.Host declared in <root>.testImportedObjectMember.importedObjectMemberWithVarargs' type=<root>.Host origin=ADAPTED_FUNCTION_REFERENCE
xs: VARARG type=kotlin.IntArray varargElementType=kotlin.Int
GET_VAR 'p0: kotlin.Int declared in <root>.testImportedObjectMember.importedObjectMemberWithVarargs' type=kotlin.Int origin=null
FUNCTION_REFERENCE 'local final fun importedObjectMemberWithVarargs (p0: kotlin.Int): kotlin.String declared in <root>.testImportedObjectMember' type=kotlin.Function1<kotlin.Int, kotlin.String> origin=ADAPTED_FUNCTION_REFERENCE reflectionTarget=public final fun importedObjectMemberWithVarargs (vararg xs: kotlin.Int): kotlin.String declared in <root>.Host