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: "extract method" creates invalid code when extracting free "continue" statement #63394

Open
adonovan opened this issue Oct 5, 2023 · 0 comments
Assignees
Labels
gopls Issues related to the Go language server, gopls. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

adonovan commented Oct 5, 2023

When extracting statements from the body of a loop that include continue, but not the enclosing loop, gopls seems not to notice the implications of the continue statement, and this generates invalid code. Extracting:

func f(cond bool) {
	for range "abc" {
|		if cond {
|			continue
|		}
|		println(0)
	}
}

becomes:

func f(cond bool) {
	for range "abc" {
		newFunction1(cond)
	}
}

func newFunction1(cond bool) {
	if cond {
		continue // error: continue not in loop
	}
	println(0)
}

This is a pity since the extract logic seems to go to great trouble to deal with return continuations.

@adonovan adonovan added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. Refactoring Issues related to refactoring tools labels Oct 5, 2023
@gopherbot gopherbot added this to the Unreleased milestone Oct 5, 2023
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.15.0 Oct 12, 2023
@findleyr findleyr modified the milestones: gopls/v0.15.0, gopls/v0.16.0 Jan 17, 2024
@findleyr findleyr modified the milestones: gopls/v0.16.0, gopls/v0.17.0 May 23, 2024
@findleyr findleyr self-assigned this Nov 14, 2024
@findleyr findleyr modified the milestones: gopls/v0.17.0, gopls/v0.18.0 Nov 25, 2024
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. Refactoring Issues related to refactoring tools Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants