Source file
src/go/types/alias_test.go
1
2
3
4
5
6
7
8 package types_test
9
10 import (
11 "go/types"
12 "testing"
13 )
14
15 func TestIssue74181(t *testing.T) {
16 src := `package p
17
18 type AB = A[B]
19
20 type _ struct {
21 _ AB
22 }
23
24 type B struct {
25 f *AB
26 }
27
28 type A[T any] struct{}
29 `
30
31 pkg := mustTypecheck(src, nil, nil)
32 b := pkg.Scope().Lookup("B").Type()
33 if n, ok := b.(*types.Named); ok {
34 if s, ok := n.Underlying().(*types.Struct); ok {
35 got := s.Field(0).Type()
36 want := types.NewPointer(pkg.Scope().Lookup("AB").Type())
37 if !types.Identical(got, want) {
38 t.Errorf("wrong type for f: got %v, want %v", got, want)
39 }
40 return
41 }
42 }
43 t.Errorf("unexpected type for B: %v", b)
44 }
45
46 func TestPartialTypeCheckUndeclaredAliasPanic(t *testing.T) {
47 src := `package p
48
49 type A = B // undeclared
50 `
51
52 pkg, _ := typecheck(src, nil, nil)
53 a := pkg.Scope().Lookup("A").Type()
54 if alias, ok := a.(*types.Alias); ok {
55 got := alias.Rhs()
56 want := types.Typ[types.Invalid]
57
58 if !types.Identical(got, want) {
59 t.Errorf("wrong type for B: got %v, want %v", got, want)
60 }
61 return
62 }
63 t.Errorf("unexpected type for A: %v", a)
64 }
65
View as plain text