Skip to content

Go: slices of slices ​

Status: accepted · Date: 2026-12-02

Step 4 of the Go plan lists slices of slices as the next slice item. This record says what the proved path accepts.

The decision ​

  • [][]T, and deeper nesting such as [][][]T, is a type of the subset when []T is (Pure.elemTypeOf). It covers parameters, results, locals, var xss [][]T, literals whose elements have their type written out, such as [][]int{[]int{1}, []int{2, 3}}, len, xss[i], xss[i][j], xss = append(xss, ys) and xss[i] = ys on an owned local, and for _, ys := range xss. The output is List (List T).
  • For xss[i], the output's default element is the empty list, the zero value of []T. The output reads it only when the index is out of range, and then the statement panics first, as for slices of structs.
  • The interpreter needs no change: Eval.Val.slice already holds any values, and a nil inner slice and an empty one agree on every operation of the subset. The proof of slice literals, len and indexing covers the new element type as it is; only the keyed case needed the new refusal below.

Refused ​

  • xss[i][j] = e, which sets an element of an inner slice. The list model is exact only when no other slice shares an array that the function changes. An inner slice can share its array with another slice, such as the ys of xss[0] = ys, so this needs ownership of the inner slices.
  • A keyed literal of slices, such as [][]int{1: []int{x}}, as for structs: the gaps would need the interpreter to make the zero value of []T.
  • Inner literals without their type, such as [][]int1, as for structs.
  • xs == nil for an inner slice, like any xs == nil: a later step (see the plan).

Checks ​

tests/go/Slices.lean runs both sides on literals, var, three levels of nesting, append, xss[i] = ys, range, a parameter of type [][]int and both panics of xss[i][j], and checks each refusal. The corpus package slices gains Rows. The differential generator writes slices of slices with append, xss[i] = []T{…}, len(xss) and xss[i][j]; it does not yet range over them, because its loop body compares the element with a literal.

This page is docs/decisions/2026-12-02-go-slices-of-slices.md at commit 5f1d031.