Radar · Go · Archive · Week 6 · Feb 3 – 9, 2025
cmd/fix: automate migrations for simple deprecations
Worth knowingtooling
- What changed
- A new directive comment
//go:fix inlinecan be placed before a function declaration to indicate that migration tooling should replace calls to that function with its body where possible. - Production impact
- The source does not say.
- Try it
- Add
//go:fix inlinebefore a trivial function in a small package and rungo fix ./...to see the replacement. - Source
- github.com/golang/go/issues/32816
Understand it, then run it
Run it now
// This program demonstrates the new //go:fix inline directive.
// The directive is currently a no‑op for the compiler, but a future
// migration tool would replace calls to add with its body.
package main
import "fmt"
//go:fix inline
func add(a, b int) int {
return a + b
}
func main() {
// The call to add could be inlined by the migration tool.
fmt.Println(add(3, 4))
}
What it printed when we ran it on Go 1.27.1
7
After the change ships
go · the proposal's code; it does not compile until the change ships
// This does not compile until the //go:fix inline directive is supported.
package main
import "fmt"
//go:fix inline
func add(a, b int) int {
return a + b
}
func main() {
fmt.Println(add(3, 4))
}
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