diff --git a/cmd/vet/deadcode.go b/cmd/vet/deadcode.go index ade75b0b71..3b306c2104 100644 --- a/cmd/vet/deadcode.go +++ b/cmd/vet/deadcode.go @@ -81,7 +81,9 @@ func (d *deadState) findLabels(stmt ast.Stmt) { case *ast.BranchStmt: switch x.Tok { case token.GOTO: - d.hasGoto[x.Label.Name] = true + if x.Label != nil { + d.hasGoto[x.Label.Name] = true + } case token.BREAK: stmt := d.breakTarget diff --git a/cmd/vet/testdata/deadcode.go b/cmd/vet/testdata/deadcode.go index 3028c98bc3..5370bc32f6 100644 --- a/cmd/vet/testdata/deadcode.go +++ b/cmd/vet/testdata/deadcode.go @@ -2118,3 +2118,8 @@ var _ = func() int { } println() // ok } + +var _ = func() { + // goto without label used to panic + goto +}