aboutsummaryrefslogtreecommitdiff
path: root/test/switch5.go
diff options
context:
space:
mode:
authorJosh Bleecher Snyder <josharian@gmail.com>2016-06-05 17:28:28 -0700
committerJosh Bleecher Snyder <josharian@gmail.com>2016-08-23 05:28:33 +0000
commite26499153e938b21850a7b6b33f27bb3d98e01cd (patch)
treea0bb353abe3d7d2f3f9e9103bf83e9e88c7131aa /test/switch5.go
parentb7ac426ee31cfe4464345754745e38bc0af02a66 (diff)
downloadgo-e26499153e938b21850a7b6b33f27bb3d98e01cd.tar.gz
go-e26499153e938b21850a7b6b33f27bb3d98e01cd.zip
cmd/compile: use a map to track const switch cases
This is simpler than the sorting technique. It also allows us to simplify or eliminate some of the sorting decisions. Most important, sorting will not work when case clauses represent ranges of integers: There is no correct sort order that allows overlap detection by comparing neighbors. Using a map allows of a cheap, simple approach to ranges, namely to insert every int in the map. The equivalent approach for sorting means juggling temporary Nodes for every int, which is a lot more expensive. Change-Id: I84df3cb805992a1b04d14e0e4b2334f943e0ce05 Reviewed-on: https://go-review.googlesource.com/26766 Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'test/switch5.go')
-rw-r--r--test/switch5.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/test/switch5.go b/test/switch5.go
index bb0f5e33ad..54a11b5c9a 100644
--- a/test/switch5.go
+++ b/test/switch5.go
@@ -79,3 +79,14 @@ func f5(a [1]int) {
case [1]int{0}: // OK -- see issue 15896
}
}
+
+// Ensure duplicate const bool clauses are accepted.
+func f6() int {
+ switch {
+ case 0 == 0:
+ return 0
+ case 1 == 1: // Intentionally OK, even though a duplicate of the above const true
+ return 1
+ }
+ return 2
+}