cmd/compile: make duplicate expr cases readable

Instead of just printing the value, print the original node to make the
error more human-friendly. Also print the value if its string form is
different than the original node, to make sure it's obvious what value
was duplicated.

This means that "case '@', '@':", which used to print:

	duplicate case 64 in switch

Will now print:

	duplicate case '@' (value 64) in switch

Factor this logic out into its own function to reuse it in range cases
and any other place where we might want to print a node and its value in
the future.

Also needed to split the errorcheck files because expression switch case
duplicates are now detected earlier, so they stop the compiler before it
gets to generating the AST and detecting the type switch case
duplicates.

Fixes #20112.

Change-Id: I9009b50dec0d0e705e5de9c9ccb08f1dce8a5a99
Reviewed-on: https://go-review.googlesource.com/41852
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
diff --git a/test/switch5.go b/test/switch5.go
index 5c3b28f..ce95bf8 100644
--- a/test/switch5.go
+++ b/test/switch5.go
@@ -9,8 +9,6 @@
 
 package main
 
-import "fmt"
-
 func f0(x int) {
 	switch x {
 	case 0:
@@ -19,7 +17,7 @@
 
 	switch x {
 	case 0:
-	case int(0): // ERROR "duplicate case 0 in switch"
+	case int(0): // ERROR "duplicate case int.0. .value 0. in switch"
 	}
 }
 
@@ -46,30 +44,9 @@
 	case 0: // ERROR "duplicate case 0 in switch"
 	case int64(0):
 	case float32(10):
-	case float32(10): // ERROR "duplicate case float32\(10\) in switch"
+	case float32(10): // ERROR "duplicate case float32\(10\) .value 10. in switch"
 	case float64(10):
-	case float64(10): // ERROR "duplicate case float64\(10\) in switch"
-	}
-}
-
-func f4(e interface{}) {
-	switch e.(type) {
-	case int:
-	case int: // ERROR "duplicate case int in type switch"
-	case int64:
-	case error:
-	case error: // ERROR "duplicate case error in type switch"
-	case fmt.Stringer:
-	case fmt.Stringer: // ERROR "duplicate case fmt.Stringer in type switch"
-	case struct {
-		i int "tag1"
-	}:
-	case struct {
-		i int "tag2"
-	}:
-	case struct { // ERROR "duplicate case struct { i int .tag1. } in type switch"
-		i int "tag1"
-	}:
+	case float64(10): // ERROR "duplicate case float64\(10\) .value 10. in switch"
 	}
 }
 
@@ -99,3 +76,19 @@
 	case 1, 2, 3, 4: // ERROR "duplicate case 1"
 	}
 }
+
+// Ensure duplicates with simple literals are printed as they were
+// written, not just their values. Particularly useful for runes.
+func f8(r rune) {
+	const x = 10
+	switch r {
+	case 33, 33: // ERROR "duplicate case 33 in switch"
+	case 34, '"': // ERROR "duplicate case '"' .value 34. in switch"
+	case 35, rune('#'): // ERROR "duplicate case rune.'#'. .value 35. in switch"
+	case 36, rune(36): // ERROR "duplicate case rune.36. .value 36. in switch"
+	case 37, '$'+1: // ERROR "duplicate case '\$' \+ 1 .value 37. in switch"
+	case 'b':
+	case 'a', 'b', 'c', 'd': // ERROR "duplicate case 'b' .value 98."
+	case x, x: // ERROR "duplicate case x .value 10."
+	}
+}