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

Parsing inconsistency between 6g and gofmt #777

Closed
gopherbot opened this issue May 13, 2010 · 4 comments
Closed

Parsing inconsistency between 6g and gofmt #777

gopherbot opened this issue May 13, 2010 · 4 comments

Comments

@gopherbot
Copy link

by jimteeuwen:

What steps will reproduce the problem?
1. Check out the attached 'main.go' file.
2. Compile it:
   $ 6g main.go
3. Run the same file through gofmt and spot the difference:
   $ gofmt -w main.go

What is the expected output? What do you see instead?
I am unsure what the expected result *should* be. Is the label definition
valid inside a switch case? The compiler seems to think so, but gofmt
disagrees. Note that the error Only occurs when the label directly preceeds
a new 'case ...:' definition. Gofmt reports: 'expected statement, found 'case''

What is your $GOOS?  $GOARCH?
GOARCH=amd64
GOOS=linux

Which revision are you using?  (hg identify)
92e9a28d5886+ tip

Attachments:

  1. main.go (671 bytes)
@griesemer
Copy link
Contributor

Comment 1:

This is a gofmt (go/parser) bug. A case clause accepts a list of statements, and a
labeled statement is a 
statement (even if the statement is the empty statement). Thanks for reporting this.
- gri

Owner changed to g...@golang.org.

Status changed to Accepted.

@griesemer
Copy link
Contributor

Comment 2:

This is a 6g error. Each statement in the statement list of a case clause needs to be
terminated by a semicolon. In 
this case the statement is a labeled statement with an empty statement. It is not
followed by a semicolon, and no 
semicolon is inserted automatically because the last token on the line is a colon ":"
(according to the semicolon 
insertion rules). Both gofmt and gccgo correctly accept the program when the semicolon
is present, and refuse it 
when the semicolon is missing.

Owner changed to r...@golang.org.

@griesemer
Copy link
Contributor

Comment 3:

Labels changed: added compilerbug.

@rsc
Copy link
Contributor

rsc commented Jul 15, 2010

Comment 4:

changeset:   5818:2c58271ca95c
user:        Russ Cox <rsc@golang.org>
date:        Thu Jul 15 15:05:56 2010 -0700
summary:     gc: bug274

Status changed to Fixed.

@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

3 participants