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

cmd/compile: spurious "declared but not used" errors #50493

Open
rsc opened this issue Jan 7, 2022 · 4 comments
Open

cmd/compile: spurious "declared but not used" errors #50493

rsc opened this issue Jan 7, 2022 · 4 comments
Assignees
Labels
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Jan 7, 2022

Not a release blocker but good to fix if easy.

package p

func f() {
	x := 1
	v := 2
	switch v.(type) {
	case int:
		println(x)
	}
}
% go tool compile /tmp/x.go
/tmp/x.go:4:2: x declared but not used
/tmp/x.go:6:9: v (variable of type int) is not an interface

Looks like because the switch header couldn't type-check, the bodies were not considered. And since the bodies were not considered, it looks like x was never used. The compiler should print the real error on line 6 and not print about line 4.

@rsc rsc added the NeedsFix label Jan 7, 2022
@rsc rsc added this to the Go1.18 milestone Jan 7, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 15, 2022

Change https://golang.org/cl/378774 mentions this issue: cmd/compile: spurious "declared but not used" errors

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 16, 2022

Change https://golang.org/cl/378834 mentions this issue: cmd/compile/internal/types2: avoid declared but not used error if type switch stmt failed

@XiaodongLoong
Copy link

@XiaodongLoong XiaodongLoong commented Jan 16, 2022

@rsc
I try to fix this issue, but I found a similar issue(#50639).

@gopherbot
Copy link

@gopherbot gopherbot commented Jan 18, 2022

Change https://golang.org/cl/379117 mentions this issue: cmd/compile, go/types: fix checking of bad type switch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants