package main
import (
"fmt"
)
type S1 struct {i int; j int}
func typeName(v interface{}) string {
switch v.(type) {
case int:
return "int"
case string:
return "string"
case *S1:
return "S1"
default:
return "unknown"
}
}
func typeName2(v interface{}) string {
kk := 2
switch i := v.(type) {
case int:
assert(i + kk == 890)
return "int"
case string:
return "string"
case *S1:
_ = i
return "S1"
case []int:
return "[]int"
case map[string]int:
return "map[string]int"
case map[string][]int:
return "map[string][]int"
default:
return "unknown"
}
return "int"
}
func main() {
var s *S1;
re := typeName(s)
assert(re == "S1")
re = typeName2(888)
re2 := typeName2([]int{1})
re3 := typeName2(map[string]int{"a":1})
re4 := typeName2(map[string][]int{"a":{1}})
fmt.Println("typeswitch", re, re2, re3, re4)
assert(re == "int")
}