1// Copyright 2022 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5package p
6
7import (
8	"reflect"
9	"testing"
10)
11
12type T1 int
13type T2 int
14
15func f[P T1 | T2, _ []P]() {}
16
17var _ = f[T1]
18
19// test case from issue
20
21type BaseT interface {
22	Type1 | Type2
23}
24type BaseType int
25type Type1 BaseType
26type Type2 BaseType // float64
27
28type ValueT[T BaseT] struct {
29	A1 T
30}
31
32func NewType1() *ValueT[Type1] {
33	r := NewT[Type1]()
34	return r
35}
36func NewType2() *ValueT[Type2] {
37	r := NewT[Type2]()
38	return r
39}
40
41func NewT[TBase BaseT, TVal ValueT[TBase]]() *TVal {
42	ret := TVal{}
43	return &ret
44}
45func TestGoType(t *testing.T) {
46	r1 := NewType1()
47	r2 := NewType2()
48	t.Log(r1, r2)
49	t.Log(reflect.TypeOf(r1), reflect.TypeOf(r2))
50	fooT1(r1.A1)
51	fooT2(r2.A1)
52}
53
54func fooT1(t1 Type1) {
55
56}
57func fooT2(t2 Type2) {
58
59}
60