-
Notifications
You must be signed in to change notification settings - Fork 17.4k
/
issue67547.go
96 lines (81 loc) · 1.82 KB
/
issue67547.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package p
func _[P int]() {
type A = P
_ = A(0) // don't crash with this conversion
}
func _[P []int]() {
type A = P
_ = make(A, 10) // don't report an error for A
}
func _[P string]() {
var t []byte
type A = P
var s A
copy(t, s) // don't report an error for s
}
func _[P map[int]int]() {
type A = P
var m A
clear(m) // don't report an error for m
}
type S1 struct {
x int "S1.x"
}
type S2 struct {
x int "S2.x"
}
func _[P1 S1, P2 S2]() {
type A = P1
var p A
_ = P2(p) // conversion must be valid
}
func _[P1 S1, P2 S2]() {
var p P1
type A = P2
_ = A(p) // conversion must be valid
}
func _[P int | string]() {
var p P
type A = int
// preserve target type name A in error messages when using Alias types
// (test are run with and without Alias types enabled, so we need to
// keep both A and int in the error message)
_ = A(p /* ERRORx `cannot convert string \(in P\) to type (A|int)` */)
}
func _[P struct{ x int }]() {
var x struct{ x int }
type A = P
var _ A = x // assignment must be valid
}
func _[P struct{ x int }]() {
type A = P
var x A
var _ struct{ x int } = x // assignment must be valid
}
func _[P []int | struct{}]() {
type A = []int
var a A
var p P
// preserve target type name A in error messages when using Alias types
a = p // ERRORx `cannot assign struct{} \(in P\) to (A|\[\]int)`
_ = a
}
func _[P any]() {
type A = P
var x A
// keep "constrained by" for aliased type parameters in error messages
var _ int = x // ERRORx `cannot use x \(variable of type (A|P) constrained by any\) as int value in variable declaration`
}
// Test case for go.dev/issue/67540.
func _() {
type (
S struct{}
A = *S
T S
)
var p A
_ = (*T)(p)
}