* new_name_list [[type] = expr_list]
*/
func constiter(vl *NodeList, t *Node, cl *NodeList) *NodeList {
+ lno := int32(0) // default is to leave line number alone in listtreecopy
if cl == nil {
if t != nil {
Yyerror("const declaration cannot have type without expression")
}
cl = lastconst
t = lasttype
+ lno = vl.N.Lineno
} else {
lastconst = cl
lasttype = t
}
-
- cl = listtreecopy(cl)
+ cl = listtreecopy(cl, lno)
var v *Node
var c *Node
orderexpr(&n.Left, order, nil)
n.Left = ordersafeexpr(n.Left, order)
- tmp1 := treecopy(n.Left)
+ tmp1 := treecopy(n.Left, 0)
if tmp1.Op == OINDEXMAP {
tmp1.Etype = 0 // now an rvalue not an lvalue
}
return r
}
-func treecopy(n *Node) *Node {
+// treecopy recursively copies n, with the exception of
+// ONAME, OLITERAL, OTYPE, and non-iota ONONAME leaves.
+// Copies of iota ONONAME nodes are assigned the current
+// value of iota_. If lineno != 0, it sets the line number
+// of newly allocated nodes to lineno.
+func treecopy(n *Node, lineno int32) *Node {
if n == nil {
return nil
}
m = Nod(OXXX, nil, nil)
*m = *n
m.Orig = m
- m.Left = treecopy(n.Left)
- m.Right = treecopy(n.Right)
- m.List = listtreecopy(n.List)
+ m.Left = treecopy(n.Left, lineno)
+ m.Right = treecopy(n.Right, lineno)
+ m.List = listtreecopy(n.List, lineno)
+ if lineno != -1 {
+ m.Lineno = lineno
+ }
if m.Defn != nil {
panic("abort")
}
*m = *n
m.Iota = iota_
+ if lineno != 0 {
+ m.Lineno = lineno
+ }
break
}
fallthrough
return et
}
-func listtreecopy(l *NodeList) *NodeList {
+func listtreecopy(l *NodeList, lineno int32) *NodeList {
var out *NodeList
for ; l != nil; l = l.Next {
- out = list(out, treecopy(l.N))
+ out = list(out, treecopy(l.N, lineno))
}
return out
}
--- /dev/null
+// 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.
+
+// Tests correct reporting of line numbers for errors involving iota,
+// Issue #8183.
+package foo
+
+const (
+ ok = byte(iota + 253)
+ bad
+ barn
+ bard // ERROR "constant 256 overflows byte"
+)
+
+const (
+ c = len([1 - iota]int{})
+ d
+ e // ERROR "array bound must be non-negative" "const initializer len\(composite literal\) is not a constant"
+ f // ERROR "array bound must be non-negative" "const initializer len\(composite literal\) is not a constant"
+)