What it means. A tuple destructuring declaration, val (a, b) = pair or var (a, b) = pair, has a type annotation, has no initializer, has more than one expression on the right, or binds a different number of names than the tuple has components. A destructuring takes every name’s type from the one tuple it splits, one name per component.
package main
func bounds() Tuple[int, int] = (3, 9)
func main() {
var (lo, hi) Tuple[int, int] = bounds()
lo = lo * 2
Println(s"$lo..$hi")
}
error[GALA-E0056]: a tuple destructuring `var (...)` takes no type annotation
--> main.gala:6:18
|
6 | var (lo, hi) Tuple[int, int] = bounds()
| ^^^^^^^^^^^^^^^ remove the type
|
= hint: remove the type; each name takes its type from the tuple
A destructuring with no tuple to split:
error[GALA-E0056]: a tuple destructuring `var (...)` needs an initializer
--> main.gala:4:5
|
4 | var (lo, hi)
| ^^^^^^^^^^^^ add the tuple to split: `= pair`
|
= hint: add the tuple to split: `= pair`; a variable with no value declares its own type instead, as in `var a int`
Write the tuple after = and let each name take its component’s type:
package main
func bounds() Tuple[int, int] = (3, 9)
func main() {
var (lo, hi) = bounds()
lo = lo * 2
Println(s"$lo..$hi")
}
To declare variables that start without a value, declare each one with its own type, var lo int, rather than as a destructuring.
val and var share their grammar with the plain val a T = x form, so the type and initializer slots parse after a tuple pattern too. An annotation there would name the tuple’s type rather than any variable’s, and a destructuring with no tuple has nothing to take types or values from. Before this code, var (a, b) stopped the transpiler with an internal error.
The grammar ignores newlines between a declaration’s parts, so var (lo, hi) followed by lo = 3 on the next line parses lo as a type. The declaration as written still has no initializer, and that is what the error reports.