]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use correct line number for := (LCOLAS)
authorRobert Griesemer <gri@golang.org>
Fri, 27 Nov 2015 23:27:14 +0000 (15:27 -0800)
committerRobert Griesemer <gri@golang.org>
Sat, 28 Nov 2015 03:36:00 +0000 (03:36 +0000)
- use same local variable name (lno) for line number for LCOLAS everywhere
- remove now unneeded assignment of line number to yylval.i in lexer

Fix per suggestion of mdempsky.

Fixes #13415.

Change-Id: Ie3c7f5681615042a12b81b26724b3a5d8a979c25
Reviewed-on: https://go-review.googlesource.com/17248
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/cmd/compile/internal/gc/lex.go
src/cmd/compile/internal/gc/parser.go
test/fixedbugs/issue13415.go [new file with mode: 0644]

index 6e8745caa5be7b05626c43c831dc0a8acf3dd9cd..55ba2ed3f4cdc11c0d8418281649cebab5a4dd7b 100644 (file)
@@ -1253,7 +1253,6 @@ l0:
                c1 = getc()
                if c1 == '=' {
                        c = int(LCOLAS)
-                       yylval.i = int(lexlineno)
                        goto lx
                }
 
index 22e3c4b7cfd0e949a3b6a85b85a0f7d6720a1bde..20a1202d2530e9876bead525962c5d3b61ddfc68 100644 (file)
@@ -717,7 +717,7 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
                return stmt
 
        case LCOLAS:
-               line := lineno
+               lno := lineno
                p.next()
 
                if rangeOk && p.got(LRANGE) {
@@ -746,7 +746,7 @@ func (p *parser) simple_stmt(labelOk, rangeOk bool) *Node {
                        } // it's a colas, so must not re-use an oldname
                        return ts
                }
-               return colas(lhs, rhs, int32(line))
+               return colas(lhs, rhs, int32(lno))
 
        default:
                p.syntax_error("expecting := or = or comma")
@@ -849,6 +849,7 @@ func (p *parser) case_(tswitch *Node) *Node {
 
                case LCOLAS:
                        // LCASE expr_or_type_list LCOLAS expr ':'
+                       lno := lineno
                        p.next()
                        rhs := p.expr()
 
@@ -857,7 +858,7 @@ func (p *parser) case_(tswitch *Node) *Node {
                        // done in casebody()
                        markdcl() // matching popdcl in caseblock
                        stmt := Nod(OXCASE, nil, nil)
-                       stmt.List = list1(colas(cases, list1(rhs), int32(p.op)))
+                       stmt.List = list1(colas(cases, list1(rhs), int32(lno)))
 
                        p.want(':') // consume ':' after declaring select cases for correct lineno
                        return stmt
diff --git a/test/fixedbugs/issue13415.go b/test/fixedbugs/issue13415.go
new file mode 100644 (file)
index 0000000..989a1ed
--- /dev/null
@@ -0,0 +1,19 @@
+// errorcheck
+
+// Copyright 2015 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Verify that error message regarding := appears on
+// correct line (and not on the line of the 2nd :=).
+
+package p
+
+func f() {
+    select {
+    case x, x := <-func() chan int { // ERROR "x repeated on left side of :="
+            c := make(chan int)
+            return c
+    }():
+    }
+}