aboutsummaryrefslogtreecommitdiff
path: root/test/goto.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-04-07 15:41:45 -0700
committerRobert Griesemer <gri@golang.org>2017-04-19 00:36:34 +0000
commit912a638b0c759fdd6c04d3c3a426157d2285a855 (patch)
treefcb8f8c28ff5728c3a2d66ec5fd8c9d91011403e /test/goto.go
parent1e3570ac86f6aeb7f8ce70b5ad236a5dd92ec804 (diff)
downloadgo-912a638b0c759fdd6c04d3c3a426157d2285a855.tar.gz
go-912a638b0c759fdd6c04d3c3a426157d2285a855.zip
cmd/compile: check labels and branches during parse time
Instead of a separate check control flow pass (checkcfg.go) operating on nodes, perform this check at parse time on the new syntax tree. Permits this check to be done concurrently, and doesn't depend on the specifics of the symbol's dclstack implementation anymore. The remaining dclstack uses will be removed in a follow-up change. - added CheckBranches Mode flag (so we can turn off the check if we only care about syntactic correctness, e.g. for tests) - adjusted test/goto.go error messages: the new branches checker only reports if a goto jumps into a block, but not which block (we may want to improve this again, eventually) - also, the new branches checker reports one variable that is being jumped over by a goto, but it may not be the first one declared (this is fine either way) - the new branches checker reports additional errors for fixedbugs/issue14006.go (not crucial to avoid those errors) - the new branches checker now correctly reports only variable declarations being jumped over, rather than all declarations (issue 8042). Added respective tests. Fixes #8042. Change-Id: I53b6e1bda189748e1e1fb5b765a8a64337c27d40 Reviewed-on: https://go-review.googlesource.com/39998 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/goto.go')
-rw-r--r--test/goto.go64
1 files changed, 32 insertions, 32 deletions
diff --git a/test/goto.go b/test/goto.go
index f456901a90..6630fb7e34 100644
--- a/test/goto.go
+++ b/test/goto.go
@@ -77,7 +77,7 @@ L:
// error shows first offending variable
func _() {
- goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
+ goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto L jumps over declaration of y at LINE+3|goto jumps over declaration"
x := 1 // GCCGO_ERROR "defined here"
_ = x
y := 1
@@ -87,7 +87,7 @@ L:
// goto not okay even if code path is dead
func _() {
- goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto jumps over declaration"
+ goto L // ERROR "goto L jumps over declaration of x at LINE+1|goto L jumps over declaration of y at LINE+3|goto jumps over declaration"
x := 1 // GCCGO_ERROR "defined here"
_ = x
y := 1
@@ -114,7 +114,7 @@ L:
// goto into inner block not okay
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
{ // GCCGO_ERROR "block starts here"
L:
}
@@ -125,12 +125,12 @@ func _() {
{ // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
// error shows first (outermost) offending block
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
{
{
{ // GCCGO_ERROR "block starts here"
@@ -142,7 +142,7 @@ func _() {
// error prefers block diagnostic over declaration diagnostic
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+3|goto L jumps into block|goto jumps into block"
x := 1
_ = x
{ // GCCGO_ERROR "block starts here"
@@ -179,14 +179,14 @@ L:
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
if true { // GCCGO_ERROR "block starts here"
L:
}
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
if true { // GCCGO_ERROR "block starts here"
L:
} else {
@@ -194,7 +194,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
if true {
} else { // GCCGO_ERROR "block starts here"
L:
@@ -205,13 +205,13 @@ func _() {
if false { // GCCGO_ERROR "block starts here"
L:
} else {
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
}
func _() {
if true {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
} else { // GCCGO_ERROR "block starts here"
L:
}
@@ -219,7 +219,7 @@ func _() {
func _() {
if true {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
} else if false { // GCCGO_ERROR "block starts here"
L:
}
@@ -227,7 +227,7 @@ func _() {
func _() {
if true {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
} else if false { // GCCGO_ERROR "block starts here"
L:
} else {
@@ -241,7 +241,7 @@ func _() {
// really is LINE+1 (like in the previous test),
// even though it looks like it might be LINE+3 instead.
if true {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
} else if false {
} else { // GCCGO_ERROR "block starts here"
L:
@@ -290,7 +290,7 @@ func _() {
for { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
@@ -299,49 +299,49 @@ func _() {
L1:
}
L:
- goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto jumps into block"
+ goto L1 // ERROR "goto L1 jumps into block starting at LINE-5|goto L1 jumps into block|goto jumps into block"
}
func _() {
for i < n { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
for i = 0; i < n; i++ { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
for i = range x { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
for i = range c { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
for i = range m { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
func _() {
for i = range s { // GCCGO_ERROR "block starts here"
L:
}
- goto L // ERROR "goto L jumps into block starting at LINE-3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-3|goto L jumps into block|goto jumps into block"
}
// switch
@@ -395,7 +395,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
switch i {
case 0:
L: // GCCGO_ERROR "block starts here"
@@ -403,7 +403,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
switch i {
case 0:
L: // GCCGO_ERROR "block starts here"
@@ -413,7 +413,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
switch i {
case 0:
default:
@@ -424,7 +424,7 @@ func _() {
func _() {
switch i {
default:
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
case 0:
L: // GCCGO_ERROR "block starts here"
}
@@ -436,7 +436,7 @@ func _() {
L: // GCCGO_ERROR "block starts here"
;
default:
- goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-4|goto L jumps into block|goto jumps into block"
}
}
@@ -492,7 +492,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+2|goto L jumps into block|goto jumps into block"
select {
case c <- 1:
L: // GCCGO_ERROR "block starts here"
@@ -500,7 +500,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+2|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+2|goto L jumps into block|goto jumps into block"
select {
case c <- 1:
L: // GCCGO_ERROR "block starts here"
@@ -510,7 +510,7 @@ func _() {
}
func _() {
- goto L // ERROR "goto L jumps into block starting at LINE+3|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+3|goto L jumps into block|goto jumps into block"
select {
case <-c:
default:
@@ -521,7 +521,7 @@ func _() {
func _() {
select {
default:
- goto L // ERROR "goto L jumps into block starting at LINE+1|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE+1|goto L jumps into block|goto jumps into block"
case <-c:
L: // GCCGO_ERROR "block starts here"
}
@@ -533,6 +533,6 @@ func _() {
L: // GCCGO_ERROR "block starts here"
;
default:
- goto L // ERROR "goto L jumps into block starting at LINE-4|goto jumps into block"
+ goto L // ERROR "goto L jumps into block starting at LINE-4|goto L jumps into block|goto jumps into block"
}
}