GoPLS Viewer

Home|gopls/cmd/stringer/testdata/typeparams/conv2.go
1// Copyright 2021 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 is a version of ../conv.go with type params
6
7// Check that constants defined as a conversion are accepted.
8
9package main
10
11import "fmt"
12
13// For now, a lone type parameter is not permitted as RHS in a type declaration (issue #45639).
14// type Other[T interface{ ~int | ~uint }] T // Imagine this is in another package.
15type Other int
16
17const (
18    // alpha Other[int] = iota
19    alpha Other = iota
20    beta
21    gamma
22    delta
23)
24
25// type Conv2 Other[int]
26type Conv2 Other
27
28const (
29    Alpha = Conv2(alpha)
30    Beta  = Conv2(beta)
31    Gamma = Conv2(gamma)
32    Delta = Conv2(delta)
33)
34
35func main() {
36    ck(Alpha"Alpha")
37    ck(Beta"Beta")
38    ck(Gamma"Gamma")
39    ck(Delta"Delta")
40    ck(42"Conv2(42)")
41}
42
43func ck(c Conv2str string) {
44    if fmt.Sprint(c) != str {
45        panic("conv2.go: " + str)
46    }
47}
48
MembersX
ck
ck.c
ck.str
fmt
Other
alpha
Conv2
main
Members
X