Skip to content

cmd/go, x/tools/go/analysis/passes/inline: //go:fix inline might change behaviour/break programs when type aliases are embedded #78230

@mateusz834

Description

@mateusz834

Consider:

type Foo int

//go:fix inline
type Bar = Foo

type _ struct {
	Bar
}
$ go fix --diff
--- /tmp/aa/main.go (old)
+++ /tmp/aa/main.go (new)
@@ -9,7 +9,7 @@
 type Bar = Foo

 type _ struct {
-	Bar
+	Foo
 }

Bar should never be inlined automatically (when embedded), since that changes the field name from Bar to Foo.

I noted that during the read of https://go.dev/blog/inliner where there is a mention that:

In principle the transformation should not change the program’s behavior (barring code that inspects the call stack, of course)

I assume this also is in regard to types?

CC @adonovan

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.FixPendingIssues that have a fix which has not yet been reviewed or submitted.RefactoringIssues related to refactoring tools

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions