• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2020 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
5// This file contains basic generic code snippets.
6
7package p
8
9// type parameter lists
10type B[P any] struct{}
11type _[P interface{}] struct{}
12type _[P B] struct{}
13type _[P B[P]] struct{}
14
15type _[A, B, C any] struct{}
16type _[A, B, C B] struct{}
17type _[A, B, C B[A, B, C]] struct{}
18type _[A1, A2 B1, A3 B2, A4, A5, A6 B3] struct{}
19
20type _[A interface{}] struct{}
21type _[A, B interface{ m() }] struct{}
22
23type _[A, B, C any] struct{}
24
25// in functions
26func _[P any]()
27func _[P interface{}]()
28func _[P B]()
29func _[P B[P]]()
30
31// type instantiations
32type _ T[int]
33
34// in expressions
35var _ = T[int]{}
36
37// in embedded types
38type _ struct{ T[int] }
39
40// interfaces
41type _ interface {
42	m()
43	~int
44}
45
46type _ interface {
47	~int | ~float | ~string
48	~complex128
49	underlying(underlying underlying) underlying
50}
51
52type _ interface {
53	T
54	T[int]
55}
56
57// tricky cases
58func _(T[P], T[P1, P2])
59func _(a [N]T)
60
61type _ struct {
62	T[P]
63	T[P1, P2]
64	f[N]
65}
66type _ interface {
67	m()
68
69	// instantiated types
70	T[ /* ERROR empty type argument list */ ]
71	T[P]
72	T[P1, P2]
73}
74