1// run
2
3// Copyright 2019 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6
7// Do not panic on conversion to anonymous interface, which
8// is similar-looking interface types in different packages.
9
10package main
11
12import (
13	"fmt"
14
15	ssa1 "issue29612.dir/p1/ssa"
16	ssa2 "issue29612.dir/p2/ssa"
17)
18
19func main() {
20	v1 := &ssa1.T{}
21	_ = v1
22
23	v2 := &ssa2.T{}
24	ssa2.Works(v2)
25	ssa2.Panics(v2) // This call must not panic
26
27	swt(v1, 1)
28	swt(v2, 2)
29}
30
31//go:noinline
32func swt(i interface{}, want int) {
33	var got int
34	switch i.(type) {
35	case *ssa1.T:
36		got = 1
37	case *ssa2.T:
38		got = 2
39
40	case int8, int16, int32, int64:
41		got = 3
42	case uint8, uint16, uint32, uint64:
43		got = 4
44	}
45
46	if got != want {
47		panic(fmt.Sprintf("switch %v: got %d, want %d", i, got, want))
48	}
49}
50