Add support for variadic function types and ellipsis in type declarations, stricter lamda types compile-time checks and object binding for Kotlin bridges

This commit is contained in:
sergeych committed 2026-02-19 11:12:39 +03:00
1 parent e7c1adb2c5
commit d82302dd01
15 files changed
+387 -12

No files matched your search

+12
View File
@@ -518,6 +518,13 @@ Examples:
fun inc(x=0) = x + 1 // (Int)->Int
fun maybe(flag) { if(flag) 1 else null } // ()->Int?
Function types are written as `(T1, T2, ...)->R`. You can include ellipsis in function *types* to
express a variadic position:
var fmt: (String, Object...)->String
var f: (Int, Object..., String)->Real
var anyArgs: (...)->Int // shorthand for (Object...)->Int
Untyped locals are allowed, but their type is fixed on the first assignment:
var x
@@ -735,6 +742,11 @@ one could be with ellipsis that means "the rest pf arguments as List":
assert( { a, b...-> [a,...b] }(100, 1, 2, 3) == [100, 1, 2, 3])
void
Type-annotated lambdas can use variadic *function types* as well:
val f: (Int, Object..., String)->Real = { a, rest..., b -> 0.0 }
val anyArgs: (...)->Int = { -> 0 }
### Using lambda as the parameter
See also: [Testing and Assertions](Testing.md)