Mastering //go:fix inline and the Source-Level Inliner in Go 1.26
Introduction
The source-level inliner introduced in Go 1.26 transforms how you modernize and refactor Go code. Unlike traditional compiler inlining that works on ephemeral intermediate representations, this tool makes durable changes to your source files. Integrated into both the go fix command and the gopls editor assistant, it allows you to replace function calls with the actual function body, substituting arguments for parameters. This guide will walk you through using //go:fix inline and the source-level inliner to automate API migrations, simplify debugging, and keep your codebase clean.

What You Need
- Go 1.26 or later – download from golang.org
- A text editor with gopls support (e.g., VS Code, GoLand, vim with gopls) – optional but recommended for interactive refactoring
- An existing Go project – can be your own or a public one to practice on
- Basic familiarity with Go syntax and the
gocommand
Step-by-Step Guide
Step 1: Upgrade to Go 1.26
First, ensure you have Go 1.26 installed. Check your current version with go version. If it’s older, download and install the latest from the official site. Verify after installation:
go versionYou should see go1.26 or later.
Step 2: Understand the //go:fix inline Directive
The directive //go:fix inline is a code comment you place above a function signature. It tells the go fix tool that calls to this function should be inlined wherever they appear. For example:
//go:fix inline
func sum(a, b int) int {
return a + b
}When you later run go fix, every call to sum(x, y) will be replaced by x + y. This is especially useful for migrating callers to a new API while keeping the transition safe and automated.
Step 3: Apply Inlining with go fix
Navigate to your module root and run:
go fixBy default, go fix applies all registered modernizers, including the source-level inliner. To restrict to only the inliner, use the -fix flag:
go fix -fix='go:fix/inline'The tool will modify your source files in place. For an inlined function like sum, a call six() that contained return sum(3, 3) becomes return 3 + 3. The original function definition is removed if no remaining calls exist, or kept otherwise.
Step 4: Interactive Inlining with gopls
If you prefer interactive refactoring, install or launch your editor with gopls support. In VS Code, open a Go file, place the cursor on a function call, open the Command Palette (Ctrl+Shift+P), search for “Source Action”, and choose “Inline call”. The editor shows a realistic preview and applies the transformation.

This uses the same underlying algorithm as go fix but gives you control over each change.
Step 5: Create Custom Modernizers for Your Own Package
As a package author, you can help users of your library keep their code up-to-date. Simply add //go:fix inline comments above deprecated or trivial functions. After users upgrade to Go 1.26, they can run go fix to automatically inline all such calls, removing dependency on old versions and improving performance. You can also combine this with other fix directives like //go:fix rewrite for more complex migrations.
Test your directives locally by running go fix -fix 'go:fix/inline' ./... on a small project that uses your package.
Tips for Success
- Start small: Add
//go:fix inlineto one or two trivial functions first and verify the output withgo fix -diffto see changes without applying them. - Beware of side effects: Inlining copies the function body, so if the function has side effects that depend on parameter evaluation order, the transformation may change behavior. The inliner is designed to preserve semantics, but always review the diff.
- Use version control: Commit your code before running
go fixso you can inspect and discard changes if needed. - Combine with other modernizers: Go 1.26 includes several built-in modernizers. Run
go fix -listto see all available. - Contributing: If you find a bug or missing feature in the inliner, report it at the Go issue tracker. The tool is actively developed.
By mastering //go:fix inline and the source-level inliner, you can keep your Go codebase modern with minimal manual effort. Embrace automated refactoring and let the tool do the heavy lifting.
Related Articles
- Python 3.15 Alpha 4: 10 Crucial Updates Every Developer Should Know
- Mastering the Dual Nature of Code: A Guide to Understanding Programming as Machine Instructions and Conceptual Models
- How to Set Up Continuous Profiling at Scale with Pyroscope 2.0
- Multi-Agent AI Coordination: Intuit Engineers Claim It's the Toughest Scaling Problem in Tech
- 6 Key Insights into Information-Driven Imaging System Design
- Mastering IntelliJ IDEA: Essential Q&A for Efficient Java Development
- Python 3.15.0 Alpha 3 Released: A Developer Preview of Upcoming Features
- Python 3.13.8 Released: A Maintenance Update with Critical Bug Fixes and Improvements