1 extern (C) int printf(const char* fmt, ...);
2
pass(int n)3 int pass(int n){ return n; }
4
5 struct X
6 {
7 int m;
8
opIndexX9 int opIndex(int m, int n)
10 {
11 return n;
12 }
13 }
14
15 /**********************************************/
16
17 struct S1f
18 {
opDispatch(string name,A...)19 int opDispatch(string name, A...)(A args)
20 {
21 static if (args.length)
22 return args[0];
23 else
24 return 0;
25 }
26 }
27 struct S1p
28 {
opDispatchS1p29 @property int opDispatch(string name, A...)(A args)
30 {
31 static if (args.length)
32 return args[0];
33 else
34 return 0;
35 }
36 }
test1()37 void test1()
38 {
39 S1f s1f;
40 assert(s1f.func() == 0); // ok -> ok
41 assert(s1f.func(1) == 1); // ok -> ok
42 assert(pass(s1f.func()) == 0); // ok -> ok
43 assert(pass(s1f.func(1)) == 1); // ok -> ok
44 assert(X(s1f.func()).m == 0);
45 assert(X()[0, s1f.func()] == 0);
46
47 S1p s1p;
48 assert(s1p.prop == 0); // ok -> ok
49 assert((s1p.prop = 1) == 1); // CTng -> CTng
50 assert(pass(s1p.prop) == 0); // ok -> ok
51 assert(pass(s1p.prop = 2) == 2); // CTng -> CTng
52 assert(X(s1p.prop).m == 0);
53 assert(X()[0, s1p.prop] == 0);
54 }
55
56 /**********************************************/
57
58 struct S2f
59 {
opDispatchS2f60 template opDispatch(string name)
61 {
62 int opDispatch(A...)(A args)
63 {
64 static if (args.length)
65 return args[0];
66 else
67 return 0;
68 }
69 }
70 }
71 struct S2p
72 {
opDispatch(string name)73 template opDispatch(string name)
74 {
75 @property int opDispatch(A...)(A args)
76 {
77 static if (args.length)
78 return args[0];
79 else
80 return 0;
81 }
82 }
83 }
test2()84 void test2()
85 {
86 S2f s2f;
87 assert(s2f.func() == 0); // ok -> ok
88 assert(s2f.func(1) == 1); // ok -> ok
89 assert(pass(s2f.func()) == 0); // ok -> ok
90 assert(pass(s2f.func(1)) == 1); // ok -> ok
91 assert(X(s2f.func()).m == 0);
92 assert(X()[0, s2f.func()] == 0);
93
94 S2p s2p;
95 assert(s2p.prop == 0); // CTng -> ok
96 assert((s2p.prop = 1) == 1); // ok -> ok
97 assert(pass(s2p.prop) == 0); // CTng -> ok
98 assert(pass(s2p.prop = 2) == 2); // ok -> ok
99 assert(X(s2p.prop).m == 0);
100 assert(X()[0, s2p.prop] == 0);
101 }
102
103 /**********************************************/
104
105 struct S3f
106 {
opDispatchS3f107 template opDispatch(string name)
108 {
109 template opDispatch(T)
110 {
111 int opDispatch(A...)(A args)
112 {
113 static if (args.length)
114 return args[0];
115 else
116 return 0;
117 }
118 }
119 }
120 }
121 struct S3p
122 {
opDispatch(string name)123 template opDispatch(string name)
124 {
125 template opDispatch(T)
126 {
127 @property int opDispatch(A...)(A args)
128 {
129 static if (args.length)
130 return args[0];
131 else
132 return 0;
133 }
134 }
135 }
136 }
test3()137 void test3()
138 {
139 S3f s3f;
140 assert(s3f.func!int() == 0); // ok -> ok
141 assert(s3f.func!int(1) == 1); // ok -> ok
142 assert(pass(s3f.func!int()) == 0); // ok -> ok
143 assert(pass(s3f.func!int(1)) == 1); // ok -> ok
144 assert(X(s3f.func!int()).m == 0);
145 assert(X()[0, s3f.func!int()] == 0);
146
147 S3p s3p;
148 assert(s3p.prop!int == 0); // CTng -> ok
149 assert((s3p.prop!int = 1) == 1); // ok -> ok
150 assert(pass(s3p.prop!int) == 0); // CTng -> ok
151 assert(pass(s3p.prop!int = 2) == 2); // ok -> ok
152 assert(X(s3p.prop!int).m == 0);
153 assert(X()[0, s3p.prop!int] == 0);
154 }
155
156 /**********************************************/
157
158 struct S4f
159 {
opDispatchS4f160 ref int opDispatch(string name, A...)(A args)
161 {
162 static int n;
163 n = args.length;
164 return n;
165 }
166 }
167 struct S4p
168 {
opDispatch(string name,A...)169 @property ref int opDispatch(string name, A...)(A args)
170 {
171 static int n;
172 n = args.length;
173 return n;
174 }
175 }
test4()176 void test4()
177 {
178 S4f s4f;
179 assert(s4f.func == 0); // getter
180 assert((s4f.func = 1) == 1); // setter
181
182 S4p s4p;
183 assert(s4p.prop == 0); // getter
184 assert((s4p.prop = 1) == 1); // setter
185 }
186
187 /**********************************************/
188
189 struct S5f
190 {
opDispatchS5f191 template opDispatch(string name)
192 {
193 ref int opDispatch(A...)(A args)
194 {
195 static int n;
196 n = args.length;
197 return n;
198 }
199 }
200 }
201 struct S5p
202 {
opDispatch(string name)203 template opDispatch(string name)
204 {
205 @property ref int opDispatch(A...)(A args)
206 {
207 static int n;
208 n = args.length;
209 return n;
210 }
211 }
212 }
test5()213 void test5()
214 {
215 S5f s5f;
216 assert(s5f.prop == 0); // getter ng -> ok
217 assert((s5f.prop = 1) == 1); // setter
218
219 S5p s5p;
220 assert(s5p.prop == 0); // getter ng -> ok
221 assert((s5p.prop = 1) == 1); // setter
222 }
223
224 /**********************************************/
225
226 struct S6f
227 {
opDispatchS6f228 template opDispatch(string name)
229 {
230 template opDispatch(T)
231 {
232 ref int opDispatch(A...)(A args)
233 {
234 static int n;
235 n = args.length;
236 return n;
237 }
238 }
239 }
240 }
241 struct S6p
242 {
opDispatch(string name)243 template opDispatch(string name)
244 {
245 template opDispatch(T)
246 {
247 @property ref int opDispatch(A...)(A args)
248 {
249 static int n;
250 n = args.length;
251 return n;
252 }
253 }
254 }
255 }
test6()256 void test6()
257 {
258 S6f s6f;
259 assert(s6f.prop!int == 0); // getter ng -> ok
260 assert((s6f.prop!int = 1) == 1); // setter
261
262 S6p s6p;
263 assert(s6p.prop!int == 0); // getter ng -> ok
264 assert((s6p.prop!int = 1) == 1); // setter
265 }
266
267 /**********************************************/
268 // 7578
269
270 struct Foo7578
271 {
opDispatchFoo7578272 static int[] opDispatch(string op, Args...)(Args)
273 {
274 return [0];
275 }
276 }
277
test7578()278 void test7578()
279 {
280 Foo7578.attrs[0] = 1;
281 }
282
283 /**********************************************/
284
main()285 int main()
286 {
287 test1();
288 test2();
289 test3();
290 test4();
291 test5();
292 test6();
293 test7578();
294
295 printf("Success\n");
296 return 0;
297 }
298