Proposals Unofficial Go proposal tracker

Add Cursor.Unparen and Cursor.UnparenEnclosing methods

#78995 · x/tools/go/ast/inspector · low impact · Implemented ·

Analyzers that walk the syntax tree with inspector.Cursor often forget to skip parentheses. A check for x == nil might then miss (x) == nil. This proposal adds two Cursor methods that handle parentheses directly.

Cursor.Unparen moves down through any *ast.ParenExpr nodes and returns the cursor for the inner expression, like ast.Unparen. Cursor.UnparenEnclosing moves up past any enclosing parentheses and returns the first ancestor (or the cursor itself) that is not inside a ParenExpr.

// Inspect the real expression, ignoring parens.
switch e := cur.Unparen().Node().(type) {
case *ast.CallExpr:
    // ...
}

// Find the real context of an expression, ignoring parens.
if k, _ := cur.UnparenEnclosing().ParentEdge(); k == edge.CallExpr_Fun {
    // ...
}
Proposal
#78995 by mateusz834
Status
Implemented on Nov 12, 2026
Impact
low
Area
x/tools/go/ast/inspector