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 5 · Jan 26 – Feb 1, 2026

x/tools/go/ast/inspector: add (*Cursor).Valid() bool

Worth knowingtooling

What changed
The inspector package now provides a Valid() method on Cursor that reports whether the cursor is valid.
Production impact
The source does not say.
Try it
Create an inspector.Inspector, walk the AST, and call cursor.Valid() to check validity instead of comparing to the zero value.
Source
github.com/golang/go/issues/76361

Understand it, then run it

Run it now

Todaygo
// This program demonstrates how the new `Valid()` method on `Cursor` would be used.
// It defines a minimal `Cursor` type with a `Valid()` method to illustrate the API.
// In real code, you would import "golang.org/x/tools/go/ast/inspector" instead.
package main

import (
	"fmt"
)

// Cursor is a stand‑in for the real inspector.Cursor type.
type Cursor struct {
	inspector *int // nil means the cursor is invalid
}

// Valid reports whether the cursor is valid.
func (c Cursor) Valid() bool {
	return c.inspector != nil
}

func main() {
	// An invalid cursor: inspector field is nil.
	var bad Cursor
	fmt.Println("bad cursor valid?", bad.Valid()) // false

	// A valid cursor: inspector field points to something.
	x := 1
	good := Cursor{inspector: &x}
	fmt.Println("good cursor valid?", good.Valid()) // true
}

What it printed when we ran it on Go 1.27.1

bad cursor valid? false
good cursor valid? true

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