Go 1.26's go fix can automatically migrate callers of deprecated functions

Go 1.26 rebuilt the go fix command with a source-level inliner that rewrites calls to deprecated functions when a //go:fix inline directive is present. Previously, a Deprecated: comment only triggered linter warnings and did not update call sites, leaving library authors to wait years for downstream code to migrate. The new approach works by placing the directive on a thin wrapper that delegates to the replacement API, so the inliner pastes that body into each caller. The article uses the ioutil.ReadFile to os.ReadFile case and a money package example to illustrate the technique. The author also notes that some calls cannot be inlined, so developers must understand those limits before relying on go fix in a release.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in