-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
Definitely nice to haveSyntaxSyntactic and semantic improvements and sugarsSyntactic and semantic improvements and sugars
Description
Spread operator ...
Four usage contexts:
1. Variadic function params (rest)
fun foo(a, b, ...c) # c: T[] — captures remaining args
fun foo(a, b, ...c:int[]) # with explicit type...c must be the last parameter. Type is array.
2. Array spread
x = [1,2,3]
y = [4,5,6]
z = [...x, ...y] # [1,2,3,4,5,6]Expands array inside array literal. Element types must be compatible.
3. Function call spread
foo(1, 2, ...z) # z: int[] → expanded into individual argumentsPasses array elements as individual arguments. Binds to variadic parameter.
4. Struct spread
user = { name: 'Masha', age: 14 }
copy = { ...user } # shallow copy
merged = { ...user, age: 15 } # field overrideCopies struct fields. Fields after spread override earlier ones.
Implementation areas
- Tokenizer — new
TokType.Spread(...) - Parser — spread in array literal, function call, struct literal, param declarations
- TIC — variadic params, spread type propagation
- Runtime — array concat, struct merge, rest arg collection
- Errors — spread of non-array in array context, spread of non-struct in struct context, rest param must be last
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Definitely nice to haveSyntaxSyntactic and semantic improvements and sugarsSyntactic and semantic improvements and sugars