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 7 · Feb 9 – 15, 2026

x/tools/go/astutil/inspector: add Cursor.ParentEdge{Kind,Index} convenience accessors

Nice to knowtooling

What changed
Accepted as: Agreed; that is more flexible. So let's just provide both separate accessors: package inspector // golang.org/x/tools/go/ast/inspector type Cursor ... // These convenience methods return the first and second components of the result of [ParentEdge]. func (Cursor) ParentEdgeKind() edge.Kind func (Cursor) ParentEdgeIndex() int
Production impact
The source does not say.
Try it
Import golang.org/x/tools/go/ast/inspector and call c.ParentEdgeKind() in a small program.
Source
github.com/golang/go/issues/77195

Understand it, then run it

Run it now

Todaygo
// This program demonstrates how the new convenience accessors
// `ParentEdgeKind` and `ParentEdgeIndex` would be used once the
// change ships.  Since the real `golang.org/x/tools/go/ast/inspector`
// package is not available in the sandbox, we provide a minimal
// mock implementation that mimics the relevant API.

package main

import "fmt"

// --- Mock types to stand in for the real inspector package. ---

// edge.Kind is an enumeration of AST edge kinds.
type Kind int

const (
	CallExpr_Args Kind = iota
	SelectorExpr_Sel
)

// Cursor represents a position in an AST.  In the real package it
// contains many fields; here we only need the ParentEdge method.
type Cursor struct {
	kind  Kind
	index int
}

// ParentEdge returns the kind of edge from the cursor's parent to
// the cursor and the index of the cursor among its siblings.
func (c Cursor) ParentEdge() (Kind, int) {
	return c.kind, c.index
}

// ParentEdgeKind returns the first component of ParentEdge.
func (c Cursor) ParentEdgeKind() Kind {
	kind, _ := c.ParentEdge()
	return kind
}

// ParentEdgeIndex returns the second component of ParentEdge.
func (c Cursor) ParentEdgeIndex() int {
	_, idx := c.ParentEdge()
	return idx
}

// --- Example usage of the convenience accessors. ---

func main() {
	// Create a cursor that is the third argument to a function call.
	cur := Cursor{kind: CallExpr_Args, index: 2}

	// Using the new convenience methods.
	if cur.ParentEdgeKind() == CallExpr_Args {
		fmt.Println("Cursor is an argument to a call expression")
	}
	if cur.ParentEdgeIndex() == 2 {
		fmt.Println("Cursor is the third argument (index 2)")
	}
}

What it printed when we ran it on Go 1.27.1

Cursor is an argument to a call expression
Cursor is the third argument (index 2)

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