| // ISSUE: KT-67869, KT-74899 | |
| // LANGUAGE: +ResolveTopLevelLambdasAsSyntheticCallArgument | |
| // IGNORE_KLIB_RUNTIME_ERRORS_WITH_CUSTOM_FIRST_STAGE: 2.3 | |
| // ^^^ KT-74899 is fixed in 2.4.20-Beta1 | |
| fun interface MyFun { | |
| fun foo(x: String): Int | |
| } | |
| val topLevel: MyFun = { it.length } | |
| fun baz(x: MyFun = { it.length }): MyFun = x | |
| class A( | |
| val classMember: MyFun = { it.length } | |
| ) | |
| fun returnExpr(): MyFun = { it.length } | |
| fun returnExplicit(): MyFun { | |
| return { it.length } | |
| } | |
| val withGetter: MyFun | |
| get() = { it.length } | |
| lateinit var topLevelLateinit: MyFun | |
| fun box(): String { | |
| if (topLevel.foo("OK") != 2) return "fail" | |
| if (baz().foo("OK") != 2) return "fail" | |
| if (A().classMember.foo("OK") != 2) return "fail" | |
| if (returnExpr().foo("OK") != 2) return "fail" | |
| if (returnExplicit().foo("OK") != 2) return "fail" | |
| if (withGetter.foo("OK") != 2) return "fail" | |
| var local: MyFun = { it.length } | |
| if (local.foo("OK") != 2) return "fail" | |
| local = { it.length + 1 } | |
| if (local.foo("OK") != 3) return "fail" | |
| topLevelLateinit = { it.length } | |
| if (topLevelLateinit.foo("OK") != 2) return "fail" | |
| val whenResult: MyFun = when { | |
| "0".length == 1 -> { | |
| { it.length } | |
| } | |
| else -> { | |
| { it.length - 1 } | |
| } | |
| } | |
| if (whenResult.foo("OK") != 2) return "fail" | |
| val deeplyNested: MyFun = if (baz().foo("OK") != 2) { | |
| if (whenResult.foo("OK") != 2) { { it.length } } | |
| else { { it.length + 1 } } | |
| } else { | |
| if (whenResult.foo("OK") == 2) { { it.length } } | |
| else { { it.length + 1 } } | |
| } | |
| return "OK" | |
| } |