From: Russ Cox Date: Mon, 29 Jun 2015 03:12:21 +0000 (-0400) Subject: cmd/compile: allow unnamed constants to set line number X-Git-Tag: go1.5beta1~57 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=55203c7dd5a1f25ae898c5dfc1e8aeb3daeb9f1d;p=gostls13.git cmd/compile: allow unnamed constants to set line number Fixes #8836. Change-Id: Idda9f4a987e03b3bdf5e8fdb984fe56d6f84aa59 Reviewed-on: https://go-review.googlesource.com/11672 Reviewed-by: David Chase --- diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index beb3c3c386..058ae5ecdd 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -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 index 0000000000..92c18f61c0 --- /dev/null +++ b/test/fixedbugs/issue8836.go @@ -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 ".*" + ) +}