| 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 | |
| 9 | package main |
| 10 | |
| 11 | import "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. |
| 15 | type Other int |
| 16 | |
| 17 | const ( |
| 18 | // alpha Other[int] = iota |
| 19 | alpha Other = iota |
| 20 | beta |
| 21 | gamma |
| 22 | delta |
| 23 | ) |
| 24 | |
| 25 | // type Conv2 Other[int] |
| 26 | type Conv2 Other |
| 27 | |
| 28 | const ( |
| 29 | Alpha = Conv2(alpha) |
| 30 | Beta = Conv2(beta) |
| 31 | Gamma = Conv2(gamma) |
| 32 | Delta = Conv2(delta) |
| 33 | ) |
| 34 | |
| 35 | func main() { |
| 36 | ck(Alpha, "Alpha") |
| 37 | ck(Beta, "Beta") |
| 38 | ck(Gamma, "Gamma") |
| 39 | ck(Delta, "Delta") |
| 40 | ck(42, "Conv2(42)") |
| 41 | } |
| 42 | |
| 43 | func ck(c Conv2, str string) { |
| 44 | if fmt.Sprint(c) != str { |
| 45 | panic("conv2.go: " + str) |
| 46 | } |
| 47 | } |
| 48 |