|
| 1 | +======================================================================== |
| 2 | +Lambda param type |
| 3 | +======================================================================== |
| 4 | +fun measure(cb: (int) -> int) {} |
| 5 | + |
| 6 | +fun foo() { |
| 7 | + measure(fun (x) { |
| 8 | + //! ^ int |
| 9 | + }) |
| 10 | +} |
| 11 | +------------------------------------------------------------------------ |
| 12 | +ok |
| 13 | + |
| 14 | +======================================================================== |
| 15 | +Lambda param types |
| 16 | +======================================================================== |
| 17 | +fun measure(cb: (int, slice) -> int) {} |
| 18 | + |
| 19 | +fun foo() { |
| 20 | + measure(fun ( |
| 21 | + x, |
| 22 | +//! ^ int |
| 23 | + y, |
| 24 | +//! ^ slice |
| 25 | + ) { |
| 26 | + }) |
| 27 | +} |
| 28 | +------------------------------------------------------------------------ |
| 29 | +ok |
| 30 | + |
| 31 | +======================================================================== |
| 32 | +Lambda auto return type |
| 33 | +======================================================================== |
| 34 | +fun measure<T>(cb: () -> T): T {} |
| 35 | + |
| 36 | +fun foo() { |
| 37 | + val a = measure(fun () { |
| 38 | +//! ^ int |
| 39 | + return 10 |
| 40 | + }) |
| 41 | +} |
| 42 | +------------------------------------------------------------------------ |
| 43 | +ok |
| 44 | + |
| 45 | +======================================================================== |
| 46 | +Lambda nullable auto return type |
| 47 | +======================================================================== |
| 48 | +fun measure<T>(cb: (int) -> T): T {} |
| 49 | + |
| 50 | +fun foo() { |
| 51 | + val a = measure(fun (a) { |
| 52 | +//! ^ int? |
| 53 | + if (a > 10) { |
| 54 | + return null |
| 55 | + } |
| 56 | + return 10 |
| 57 | + }) |
| 58 | +} |
| 59 | +------------------------------------------------------------------------ |
| 60 | +ok |
| 61 | + |
| 62 | +======================================================================== |
| 63 | +Lambda with never auto return type |
| 64 | +======================================================================== |
| 65 | +fun measure<T>(cb: (int) -> T): T {} |
| 66 | + |
| 67 | +fun foo() { |
| 68 | + val a = measure(fun (a) { |
| 69 | +//! ^ never |
| 70 | + if (a > 10) { |
| 71 | + throw 20 |
| 72 | + } |
| 73 | + throw 10 |
| 74 | + }) |
| 75 | +} |
| 76 | +------------------------------------------------------------------------ |
| 77 | +ok |
| 78 | + |
| 79 | +======================================================================== |
| 80 | +Lambda with generic param type |
| 81 | +======================================================================== |
| 82 | +fun measure<T>(cb: (T) -> void): T {} |
| 83 | + |
| 84 | +fun foo() { |
| 85 | + val a = measure(fun (a: int) { |
| 86 | +//! ^ int |
| 87 | + }) |
| 88 | +} |
| 89 | +------------------------------------------------------------------------ |
| 90 | +ok |
| 91 | + |
| 92 | +======================================================================== |
| 93 | +Lambda with generic param type with struct |
| 94 | +======================================================================== |
| 95 | +struct S { |
| 96 | + x: int |
| 97 | +} |
| 98 | + |
| 99 | +fun measure<T>(cb: (T) -> void): T {} |
| 100 | + |
| 101 | +fun foo() { |
| 102 | + val a = measure(fun (a: S) { |
| 103 | +//! ^ S |
| 104 | + a |
| 105 | +//! ^ S |
| 106 | + .x; |
| 107 | +//! ^ int |
| 108 | + }) |
| 109 | +} |
| 110 | +------------------------------------------------------------------------ |
| 111 | +ok |
0 commit comments