]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: allow unnamed constants to set line number
authorRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 03:12:21 +0000 (23:12 -0400)
committerRuss Cox <rsc@golang.org>
Mon, 29 Jun 2015 17:35:55 +0000 (17:35 +0000)
Fixes #8836.

Change-Id: Idda9f4a987e03b3bdf5e8fdb984fe56d6f84aa59
Reviewed-on: https://go-review.googlesource.com/11672
Reviewed-by: David Chase <drchase@google.com>
src/cmd/compile/internal/gc/subr.go
test/fixedbugs/issue8836.go [new file with mode: 0644]

index beb3c3c386a0ca5c2789eac3c114b0f152cd2b3a..058ae5ecdddc7bd0a27fd98c6f150a77cf7bebe9 100644 (file)
@@ -231,9 +231,15 @@ func setlineno(n *Node) int32 {
        lno := lineno
        if n != nil {
                switch n.Op {
-               case ONAME, OTYPE, OPACK, OLITERAL:
+               case ONAME, OTYPE, OPACK:
                        break
 
+               case OLITERAL:
+                       if n.Sym != nil {
+                               break
+                       }
+                       fallthrough
+
                default:
                        lineno = n.Lineno
                        if lineno == 0 {
diff --git a/test/fixedbugs/issue8836.go b/test/fixedbugs/issue8836.go
new file mode 100644 (file)
index 0000000..92c18f6
--- /dev/null
@@ -0,0 +1,24 @@
+// 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.
+
+// Checking that line number is correct in error message.
+
+package main
+
+type Cint int
+
+func foobar(*Cint, Cint, Cint, *Cint)
+
+func main() {
+       a := Cint(1)
+
+       foobar(
+               &a,
+               0,
+               0,
+               42, // ERROR ".*"
+       )
+}