Variable as function calls.

This commit is contained in:
Dmitry Petrov
2016-08-25 10:11:38 +03:00
committed by Dmitry Petrov
parent b3407de1e6
commit 3f256fab67
8 changed files with 78 additions and 9 deletions
+6
View File
@@ -0,0 +1,6 @@
fun String.k(): () -> String = { -> this }
fun test1(f: () -> Unit) = f()
fun test2(f: String.() -> Unit) = "hello".f()
fun test3() = "hello".k()()
fun test4(ns: String?) = ns?.k()?.invoke()
+49
View File
@@ -0,0 +1,49 @@
IrFile /variableAsFunctionCall.kt
IrFunction public fun kotlin.String.k(): () -> kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
DUMMY KtLambdaExpression type=() -> kotlin.String
IrFunction public fun test1(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
CALL .invoke type=kotlin.Unit operator=INVOKE
$this: GET_VAR f type=() -> kotlin.Unit operator=VARIABLE_AS_FUNCTION
IrFunction public fun test2(/*0*/ f: kotlin.String.() -> kotlin.Unit): kotlin.Unit
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
CALL .invoke type=kotlin.Unit operator=INVOKE
$this: GET_VAR f type=kotlin.String.() -> kotlin.Unit operator=VARIABLE_AS_FUNCTION
$receiver: CONST String type=kotlin.String value='hello'
IrFunction public fun test3(): kotlin.String
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
CALL .invoke type=kotlin.String operator=null
$this: CALL .k type=() -> kotlin.String operator=null
$receiver: CONST String type=kotlin.String value='hello'
IrFunction public fun test4(/*0*/ ns: kotlin.String?): kotlin.String?
IrExpressionBody
BLOCK type=<no-type> hasResult=false operator=null
RETURN type=<no-type>
BLOCK type=kotlin.String? hasResult=true operator=SAFE_CALL
VAR val tmp1_safe_receiver: (() -> kotlin.String)?
BLOCK type=(() -> kotlin.String)? hasResult=true operator=SAFE_CALL
VAR val tmp0_safe_receiver: kotlin.String?
GET_VAR ns type=kotlin.String? operator=null
WHEN type=(() -> kotlin.String)? operator=SAFE_CALL
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp0_safe_receiver type=kotlin.String? operator=null
arg1: CONST Null type=kotlin.Nothing? value='null'
then: CONST Null type=kotlin.Nothing? value='null'
else: CALL .k type=() -> kotlin.String operator=null
$this: GET_VAR tmp0_safe_receiver type=kotlin.String? operator=null
WHEN type=kotlin.String? operator=SAFE_CALL
if: CALL .EQEQ type=kotlin.Boolean operator=EQEQ
arg0: GET_VAR tmp1_safe_receiver type=(() -> kotlin.String)? operator=null
arg1: CONST Null type=kotlin.Nothing? value='null'
then: CONST Null type=kotlin.Nothing? value='null'
else: CALL .invoke type=kotlin.String operator=null
$this: GET_VAR tmp1_safe_receiver type=(() -> kotlin.String)? operator=null