8000 x/tools/gopls: Definition: out-of-bounds panic · Issue #73797 · golang/go · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
x/tools/gopls: Definition: out-of-bounds panic #73797
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

Open
adonovan opened this issue May 20, 2025 · 4 comments
Open

x/tools/gopls: Definition: out-of-bounds panic #73797

adonovan opened this issue May 20, 2025 · 4 comments
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member
#!stacks
"runtime.goPanicIndex:+2" && "Definition:+107"

Issue created by stacks.

	case token.BREAK, token.CONTINUE:
			// Find innermost relevant ancestor for break/continue.
			for i, n := range path[1:] {
				if isLabeled {
					l, ok := path[1:][i+1].(*ast.LabeledStmt) <--- panic (on last iteration of range loop, i+1 is OOB)
					if !(ok && l.Label.Name == label.Name()) {
						continue
					}
				}

This stack ChWbnw was reported by telemetry:

golang.org/x/tools/gopls@v0.18.1 go1.23.6 windows/amd64 vscode (2)
@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels May 20, 2025
@gopherbot gopherbot added this to the Unreleased milestone May 20, 2025
@
8000
adonovan adonovan modified the milestones: Unreleased, gopls/v0.19.0 May 20, 2025
@madelinekalil
Copy link
madelinekalil commented May 20, 2025

Was able to reproduce this with the following code:

func F() {
    label:
	for i := range 10 {
	}
	for i := range 10 {
		continue label
	}
}

This compiles but there is a typecheck error since the label corresponds to a different loop. With the path[1:][i+1].(*ast.LabeledStmt) check we are assuming we will find the label on the enclosing path, which is not the case for this example. I guess we just have to add a check that i has not exceeded the length of the path and if it has, return early.

@mateusz834
Copy link
Member

This compiles but there is a typecheck error since the label corresponds to a different loop

Note that it only ends up with a typecheck error if you are using gotip to compile gopls.

See #70974

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/674497 mentions this issue: gopls/internal/golang: fix crash in definition of invalid "continue label"

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/675017 mentions this issue: gopls/internal/golang: fix crash in definition of invalid "continue label"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants
0