Archive · Week 37 · Sep 7 – 13, 2026from 3 items
The Go team has focused on improving tooling and documentation. Three proposals were accepted: a clearer statement of supported version‑control system versions for `go get`, an enhancement to `goimports` that repairs import grouping and ordering, and a refactor of the cgo front‑end so that the compiler can work with unmodified Go source.
Worth knowingcompiler
cmd/cgo: arrange to pass unmodified Go source files to compiler, go/types
- What changed
- The analysis logic for cgo has been extracted into an internal package that can be reused by
cmd/compileandgo/typeswithout rewriting source files. - Production impact
- The source does not say.
- Try it
- Build a cgo package with
go buildand note any changes in error messages or diagnostics. - Source
- github.com/golang/go/issues/16623
Exercise
Exercise – Using //line directives to keep original source positions
In Go, a //line comment can be used to tell the compiler that a piece of code actually comes from another file (or line). This is handy when a tool rewrites Go code but still wants error messages to point to the original source. Write a small program that:
1. Parses a Go source file that contains a //line directive pointing to a different file. 2. Finds the position of the identifier foo in the parsed AST. 3. Prints the file name and line number that the compiler would report for that identifier.
You should see that the reported position comes from the file specified in the //line directive, not the file that actually contains the code.
---
package main
import (
"fmt"
"go/parser"
"go/token"
)
func main() {
// The source code is in a string for simplicity.
src := `package main
//line other.go:10
var foo int
`
fset := token.NewFileSet()
_, err := parser.ParseFile(fset, "main.go", src, parser.ParseComments)
if err != nil {
panic(err)
}
// TODO: Find the position of the identifier "foo" and print the file
// name and line number that the compiler would report.
}
Show a solution
package main
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
)
func main() {
src := `package main
//line other.go:10
var foo int
`
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "main.go", src, parser.ParseComments)
if err != nil {
panic(err)
}
// Walk the AST to find the identifier "foo".
var pos token.Position
ast.Inspect(f, func(n ast.Node) bool {
if id, ok := n.(*ast.Ident); ok && id.Name == "foo" {
pos = fset.Position(id.Pos())
return false // stop walking
}
return true
})
fmt.Printf("Identifier 'foo' is reported at %s:%d\n", pos.Filename, pos.Line)
}
What it printed when we ran it on Go 1.27.1
Identifier 'foo' is reported at other.go:10
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.
The 60-second version
Hello, I’m here to share a few updates from the Go team this week. First, the installation guide now specifies the minimum supported versions of version‑control systems that the `go get` command relies on, so you know exactly which Git, Mercurial, or other tools will work with Go. Second, the `goimports` tool has been enhanced to automatically repair import grouping and ordering, so your imports will always be neatly sorted without extra effort. Finally, the cgo front‑end has been refactored to allow the compiler and type‑checker to work directly with unmodified Go source, which should improve error messages and position information for cgo‑using packages. Those are the key takeaways from this week’s work.
Written by gpt-oss-20b · claims checked against the sources · archive, not individually reviewed