IR: default parameter extension support
for code
```
fun Int.foo(a:Int, b:Int = a + 1, c:Int = a + b) = a + b +c
fun main(arg:Array<String>) {
42.foo(0)
}
```
we generate IR representation corresponding to the following code
```
fun Int.foo(a:Int, b:Int, c:Int) = a + b +c
fun foo_default(a:Int, b:Int, c:Int, __mask__:Int, __receiver__:Int):Int {
var tmpb:Int = 0
if ((__mask__ and (1 shl 1)) != 0)
tmpb = a + 1
else
tmpb = b
var tmpc:Int = 0
if ((__mask__ and (1 shl 2)) != 0)
tmpc = a + tmpb
else
tmpc = c
return __receiver__.foo(a, tmpb, tmpc)
}
fun main(arg:Array<String>) {
foo_default(0, 0, 0, 6 /* (1 shl 1) | (1 shl 2)*/, 42)
}
```
NOTE: if call provides all arguents we don't emit call of _default function.
This commit is contained in:
committed by
Konstantin Anisimov
parent
e3662bfa1e
commit
26ee99185c
+1
-1
@@ -51,7 +51,7 @@ internal class KonanLower(val context: Context) {
|
||||
Autoboxing(context).lower(irFile)
|
||||
}
|
||||
phaser.phase(KonanPhase.LOWER_INLINE) {
|
||||
//FunctionInlining(context).inline(irFile)
|
||||
FunctionInlining(context).inline(irFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user