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/gc: (x.(type)) is not a valid type switch guard #4470

Closed
griesemer opened this issue Nov 30, 2012 · 6 comments
Closed

cmd/gc: (x.(type)) is not a valid type switch guard #4470

griesemer opened this issue Nov 30, 2012 · 6 comments
Milestone

Comments

@griesemer
Copy link
Contributor

http://play.golang.org/p/P6zBJswKO9

runs w/o complaints but the type switch guard

   (x.(type))

is not valid. The spec is pretty clear as the syntax is explicitly specified: 

http://tip.golang.org/ref/spec#TypeSwitchGuard

The form of the guard is important to the meaning of the switch, so permitting ()'s here
seems not correct (for the same reason we do not permit calls in go/defer statements in
parentheses).

gccgo does not permit it:

$ gccgo x.go
x.go:5:13: error: use of '.(type)' outside type switch
  switch (x.(type)) {
             ^

The go/parser and gofmt appear to accept it but gofmt rewrites it so that the ()'s are
gone. Thus, it's unlikely that there are many such type switch guards in the wild.
@rsc
Copy link
Contributor

rsc commented Dec 3, 2012

Comment 1:

OK. Please add a test for gofmt to ensure that we keep that "accept
and rewrite" behavior.

@griesemer
Copy link
Contributor Author

Comment 2:

gofmt test: CL 6867062 .

@rsc
Copy link
Contributor

rsc commented Dec 9, 2012

Comment 3:

Labels changed: added priority-later, go1.1, removed priority-triage, go1.1maybe.

@rsc
Copy link
Contributor

rsc commented Dec 10, 2012

Comment 4:

Labels changed: added size-s.

@DanielMorsing
Copy link
Contributor

Comment 5:

Fix at https://golang.org/cl/6949073/

@DanielMorsing
Copy link
Contributor

Comment 6:

This issue was closed by revision c956dcd.

Status changed to Fixed.

@rsc rsc added this to the Go1.1 milestone Apr 14, 2015
@rsc rsc removed the go1.1 label Apr 14, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc removed their assignment Jun 22, 2022
This issue was closed.
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

4 participants