aboutsummaryrefslogtreecommitdiffhomepage
path: root/testdata/structs.go
blob: c4ba5d29dabd358d56691de03de18fee819205c7 (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package main

// TODO: add .ll test files to check the output

type s0 struct {
}

type s1 struct {
	a byte
}

type s2 struct {
	a byte
	b byte
}

type s3 struct {
	a byte
	b byte
	c byte
}

// should not be expanded
type s4 struct {
	a byte
	b byte
	c byte
	d byte
}

// same struct, different type
type s4b struct {
	a byte
	b byte
	c byte
	d byte
}

type s5 struct {
	a struct {
		aa byte
		ab byte
	}
	b byte
}

type s6 struct {
	a string
	b byte
}

type s7 struct {
	a interface{}
	b byte
}

// should not be expanded
type s8 struct {
	a []byte // 3 elements
	b byte   // 1 element
}

// linked list (recursive type)
type s9 struct {
	n    int
	next *s9
	s    []*s9
}

func test0(s s0) {
	println("test0")
}

func test1(s s1) {
	println("test1", s.a)
}

func test2(s s2) {
	println("test2", s.a, s.b)
}

func test3(s s3) {
	println("test3", s.a, s.b, s.c)
}

func test4(s s4) {
	println("test4", s.a, s.b, s.c, s.d)
	test4b(s4b(s))
	test4bp((*s4b)(&s))
}

func test4b(s s4b) {
	println("test4b", s.a, s.b, s.c, s.d)
}

func test4bp(s *s4b) {
	println("test4bp", s.a, s.b, s.c, s.d)
}

func test5(s s5) {
	println("test5", s.a.aa, s.a.ab, s.b)
}

func test6(s s6) {
	println("test6", s.a, len(s.a), s.b)
}

func test7(s s7) {
	println("test7", s.a, s.b)
}

func test8(s s8) {
	println("test8", len(s.a), cap(s.a), s.a[0], s.a[1], s.b)
}

func test9(s s9) {
	println("test9", s.next.next)
}

func main() {
	test0(s0{})
	test1(s1{1})
	test2(s2{1, 2})
	test3(s3{1, 2, 3})
	test4(s4{1, 2, 3, 4})
	test5(s5{a: struct {
		aa byte
		ab byte
	}{1, 2}, b: 3})
	test6(s6{"foo", 5})
	test7(s7{a: nil, b: 8})
	test8(s8{[]byte{12, 13, 14}[:2], 6})
	test9(s9{next: &s9{}})
}