Fixes #8042.
Change-Id: I75080f24104256065fd73b07a13c5b8e7d6da94c
Reviewed-on: https://go-review.googlesource.com/9442
Reviewed-by: Russ Cox <rsc@golang.org>
}
s = Pkglookup(d.Name, d.Pkg)
lno = int(s.Lastlineno)
+ if s.Def != nil {
+ d.whyPushed = s.Def.Op
+ }
dcopy(s, d)
d.Lastlineno = int32(lno)
if dflag() {
fs = fs.Link
}
if fs != to.Sym {
+ // more declarations at label than at goto.
+ // figure out if they are all types.
+ ts := to.Sym
+ ntt := nt
+ for ; ntt > nf; ntt-- {
+ if ts.whyPushed != OTYPE {
+ break
+ }
+ ts = ts.Link
+ }
+ // all types, nothing to see here.
+ if ntt == nf {
+ return
+ }
+
lno := int(lineno)
setlineno(from)
var block *Sym
var dcl *Sym
- ts := to.Sym
+ ts = to.Sym
for ; nt > nf; nt-- {
if ts.Pkg == nil {
block = ts
- } else {
+ } else if ts.whyPushed != OTYPE {
dcl = ts
}
ts = ts.Link
for ts != fs {
if ts.Pkg == nil {
block = ts
- } else {
+ } else if ts.whyPushed != OTYPE {
dcl = ts
}
ts = ts.Link
Uniqgen uint32
Importdef *Pkg // where imported definition was found
Linkname string // link name
+ whyPushed uint8 // why this symbol pushed onto dclstack. Same as Node.Op. Used by goto validation
// saved and restored by dcopy
Pkg *Pkg
goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
}
}
+
+// issue 8042
+func _() {
+ goto L
+ type a int
+ L:
+}
+
+// make sure we only complain about variable declarations.
+func _() {
+ goto L // ERROR "goto L jumps over declaration of x at LINE+2|goto jumps over declaration"
+ type a int
+ x := 1 // GCCGO_ERROR "defined here"
+ _ = x
+L:
+}