aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2010-06-08 17:06:26 -0700
committerRobert Griesemer <gri@golang.org>2010-06-08 17:06:26 -0700
commit3f3ff2bd5c1bd9aeb73792c72451438b8099001b (patch)
tree56ec9e27c011dce161601ec3eb4bb5b8a9cfb215
parentf892540513d398156f32b357bcda43fe62f13728 (diff)
downloadgo-3f3ff2bd5c1bd9aeb73792c72451438b8099001b.tar.gz
go-3f3ff2bd5c1bd9aeb73792c72451438b8099001b.zip
go/parser: correct position of empty statement ';'
(caused certain files to not be idempotent under gofmt) - corrected golden files for go/printer - slightly simplified some code in nodes.go (no impact on formatting) - these changes have no impact on gofmt output of .go files under src, misc fallthrough statement considered harmful! R=rsc CC=golang-dev https://golang.org/cl/1593042
-rw-r--r--src/pkg/go/parser/parser.go5
-rw-r--r--src/pkg/go/printer/nodes.go6
-rw-r--r--src/pkg/go/printer/testdata/statements.golden8
3 files changed, 9 insertions, 10 deletions
diff --git a/src/pkg/go/parser/parser.go b/src/pkg/go/parser/parser.go
index f9264f03bb..c1914005a9 100644
--- a/src/pkg/go/parser/parser.go
+++ b/src/pkg/go/parser/parser.go
@@ -1716,8 +1716,7 @@ func (p *parser) parseForStmt() ast.Stmt {
var key, value ast.Expr
switch len(as.Lhs) {
case 2:
- value = as.Lhs[1]
- fallthrough
+ key, value = as.Lhs[0], as.Lhs[1]
case 1:
key = as.Lhs[0]
default:
@@ -1785,8 +1784,8 @@ func (p *parser) parseStmt() (s ast.Stmt) {
case token.FOR:
s = p.parseForStmt()
case token.SEMICOLON:
+ s = &ast.EmptyStmt{p.pos}
p.next()
- fallthrough
case token.RBRACE:
// a semicolon may be omitted before a closing "}"
s = &ast.EmptyStmt{p.pos}
diff --git a/src/pkg/go/printer/nodes.go b/src/pkg/go/printer/nodes.go
index 77287f82bd..a48a40790e 100644
--- a/src/pkg/go/printer/nodes.go
+++ b/src/pkg/go/printer/nodes.go
@@ -1030,12 +1030,12 @@ func (p *printer) stmt(stmt ast.Stmt, nextIsRBrace bool, multiLine *bool) {
// a "correcting" unindent immediately following a line break
// is applied before the line break if there is no comment
// between (see writeWhitespace)
- p.print(unindent, s.Pos())
+ p.print(unindent)
p.expr(s.Label, multiLine)
p.print(token.COLON, indent)
- if _, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty {
+ if e, isEmpty := s.Stmt.(*ast.EmptyStmt); isEmpty {
if !nextIsRBrace {
- p.print(newline, s.Stmt.Pos(), token.SEMICOLON)
+ p.print(newline, e.Pos(), token.SEMICOLON)
break
}
} else {
diff --git a/src/pkg/go/printer/testdata/statements.golden b/src/pkg/go/printer/testdata/statements.golden
index 9087390e7c..73a3e12368 100644
--- a/src/pkg/go/printer/testdata/statements.golden
+++ b/src/pkg/go/printer/testdata/statements.golden
@@ -259,11 +259,11 @@ L: // no semicolon needed
func _() {
switch 0 {
case 0:
- L0: // semicolon required
- ;
+ L0:
+ ; // semicolon required
case 1:
- L1: // semicolon required
- ;
+ L1:
+ ; // semicolon required
default:
L2: // no semicolon needed
}