This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Go · Archive · Week 24 · Jun 9 – 15, 2025

slices: document behavior w.r.t. nil

Worth knowingecosystem

What changed
The proposal documents the current nil‑preserving behavior of all functions in the slices package, including Clip, Clone, and Concat.
Production impact
The source does not say.
Try it
Run go test on the slices package to see the updated documentation.
Source
github.com/golang/go/issues/73604

Understand it, then run it

The slices package in Go already keeps a slice’s nil status when it does not add any elements. For example, if you call slices.Clip or slices.Clone with a nil slice, the result is still nil. When you concatenate slices with slices.Concat, the result is nil only if every input slice is empty. The change simply documents these facts in the package’s documentation, so developers know what to expect.

Run it now

Todaygo
// This program demonstrates how Go’s slice operations preserve or change nilness.
// It uses only the standard library and runs in Go 1.27.1.

package main

import (
	"fmt"
)

func main() {
	// A nil slice of ints.
	var nilSlice []int

	// 1. Converting a nil slice to a typed nil slice.
	fmt.Printf("[]int(nil) is nil: %v\n", nilSlice == nil)

	// 2. Creating an empty slice with make.
	empty := make([]int, 0)
	fmt.Printf("make([]int, 0) is nil: %v\n", empty == nil)

	// 3. Slicing a nil slice to length 0 preserves nilness.
	sliced := nilSlice[:0]
	fmt.Printf("nilSlice[:0] is nil: %v\n", sliced == nil)

	// 4. Appending to a nil slice when the result is still empty.
	appended := append(nilSlice, []int{}...)
	fmt.Printf("append(nilSlice, []int{}...) is nil: %v\n", appended == nil)

	// 5. Appending a non‑empty element to a nil slice creates a non‑nil slice.
	appendedNonEmpty := append(nilSlice, 42)
	fmt.Printf("append(nilSlice, 42) is nil: %v\n", appendedNonEmpty == nil)
}

What it printed when we ran it on Go 1.27.1

[]int(nil) is nil: true
make([]int, 0) is nil: false
nilSlice[:0] is nil: true
append(nilSlice, []int{}...) is nil: true
append(nilSlice, 42) is nil: false

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed