Skip to content

x/tools/internal/refactor/inline: reduce call if neither binding decl nor callee body would create name conflicts #70759

@adonovan

Description

@adonovan

Inlining even simple calls such as:

_ = astutil.NodeContains(p.File, typeError.Pos)

causes literalization due to the need for a binding decl within the function body:

_ = func() bool { var n ast.Node = p.File; return n.Pos() <= typeError.Pos && typeError.Pos <= n.End() }()

But the name n is not used in the caller block, so it would be fine to melt the call down to:

var n ast.Node = p.File
_ = n.Pos() <= typeError.Pos && typeError.Pos <= n.End()

FWIW, without the _ = ... assignment, the inliner does reduce the call:

{
	var n ast.Node = p.File
	_ = n.Pos() <= typeError.Pos && typeError.Pos <= n.End()
}

@findleyr

Metadata

Metadata

Assignees

No one assigned

    Labels

    RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions