Skip to content

x/tools/gopls: break in type switch highlights outer for loop #65752

@dominikh

Description

@dominikh

gopls version

golang.org/x/tools/gopls@(devel)

What did you do?

Input file:

package main

func main() {
	var x any
	for {
		switch x.(type) {
		default:
			break
		}
	}
}

CLI invocation:

$ ~/prj/bin/gopls highlight ./bar.go:8:5
Log: Loading packages...
Info: Finished loading packages.
/home/dominikh/prj/src/example.com/bar.go:5:2-5
/home/dominikh/prj/src/example.com/bar.go:8:4-9

What did you see happen?

bar.go:5:2-5 corresponds to the for keyword.

What did you expect to see?

The break statement breaks from the switch statement, not the for loop. Gopls does handle this correctly for value switches, but not for type switches.

Editor and settings

No response

Logs

No response

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeToolsThis 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

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions