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 38 · Sep 14 – 20, 2026

go/types: add Scope.Elements iterator

Worth knowingstdlib

What changed
The Scope type now has an Objects() iter.Seq[Object] method that returns an iterator over the objects in a scope in name order.
Production impact
The source does not say.
Try it
Iterate over a types.Scope with for obj := range scope.Objects() { … }.
Source
github.com/golang/go/issues/80449

Understand it, then run it

Run it now

Todaygo
// This program demonstrates how to iterate over the objects in a
// types.Scope in Go 1.27.1, where the proposed Objects() iterator
// is not yet available. It parses a small Go source file, builds
// its type information, and then walks the package scope printing
// each object's name and kind.
//
// In a future release that includes the change, the loop could be
// simplified to:
//   for obj := range pkg.Scope().Objects() { ... }
package main

import (
	"fmt"
	"go/ast"
	"go/parser"
	"go/token"
	"go/types"
)

func main() {
	// Create a file set and parse a tiny Go source snippet.
	fset := token.NewFileSet()
	src := `package main
func foo() {}
var x int`
	file, err := parser.ParseFile(fset, "example.go", src, 0)
	if err != nil {
		panic(err)
	}

	// Set up type checking for the file.
	conf := types.Config{Importer: nil}
	info := &types.Info{Defs: make(map[*ast.Ident]types.Object)}
	pkg, err := conf.Check("example", fset, []*ast.File{file}, info)
	if err != nil {
		panic(err)
	}

	// Iterate over the package scope using the existing API.
	s := pkg.Scope()
	for _, name := range s.Names() {
		obj := s.Lookup(name)
		fmt.Printf("%s: %s\n", name, obj.Type())
	}
}

What it printed when we ran it on Go 1.27.1

foo: func()
x: int

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