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: declared but not used if use type switch on type parameter value #50639

Closed
XiaodongLoong opened this issue Jan 16, 2022 · 2 comments
Closed

Comments

@XiaodongLoong
Copy link
Contributor

@XiaodongLoong XiaodongLoong commented Jan 16, 2022

What version of Go are you using (go version)?

$ go version
go version devel go1.18-3b5eec9370 Fri Jan 14 21:54:39 2022 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

package p

func f[T any](a T) {
	x := 1
	z := 3
	switch a.(type) {
	case int:
		println(x)
	}
	println(z)
}

$ bin/go tool compile t2.go 
t2.go:4:2: x declared but not used
t2.go:6:9: cannot use type switch on type parameter value a (variable of type T constrained by any)

What did you expect to see?

Don't output "x declared but not used"

What did you see instead?

It should only output as following :
t2.go:6:9: cannot use type switch on type parameter value a (variable of type T constrained by any)

@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

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 16, 2022

Thanks. Closing as dup of #50493.

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

No branches or pull requests

3 participants