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

gc: unused variable bound to closure not recognized #17968

Closed
stjj89 opened this issue Nov 17, 2016 · 1 comment
Closed

gc: unused variable bound to closure not recognized #17968

stjj89 opened this issue Nov 17, 2016 · 1 comment

Comments

@stjj89
Copy link
Contributor

stjj89 commented Nov 17, 2016

gc accepts the following snippet of code, but gccgo and go/types report that: "x declared but not used":

func myfunc() {
  var x int
  go func() {
    x = 3
  }()
}

gccgo and go/types are probably correct here. x is only ever assigned to, but never returned or used.

If I make x a return value, none of one of gc, gccgo, and go/types complain.

func myfunc() {
  var x int
  go func() int {
    x = 3
    return x
  }()
}
@ianlancetaylor
Copy link
Contributor

Dup of #8560.

@golang golang locked and limited conversation to collaborators Nov 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants