Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/gopls: refactor.extract.variable on multi-valued expression produces invalid code #70561

Closed
adonovan opened this issue Nov 25, 2024 · 2 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Nov 25, 2024

Gopls' extract logic does not correctly handle the case when an expression has multiple values:

Before:

func f(m map[string]int) {
	if v, ok := m[""]; ok { // <-- refactor.extract.variable on m[""]
		println(v)
	}
}

After:

func f(m map[string]int) {
	x := m[""]
	if v, ok := x; ok { // error: assignment mismatch
		println(v)
	}
}
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Nov 25, 2024
@gopherbot gopherbot added this to the Unreleased milestone Nov 25, 2024
@adonovan adonovan added Refactoring Issues related to refactoring tools gopls Issues related to the Go language server, gopls. help wanted and removed gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Nov 25, 2024
@adonovan adonovan self-assigned this Nov 25, 2024
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/631777 mentions this issue: gopls/internal/golang: refactor.extract.variable: allow all exprs

@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. help wanted Refactoring Issues related to refactoring tools
Projects
None yet
Development

No branches or pull requests

4 participants