1 // PERMUTE_ARGS: -property
3 extern (C
) int printf(const char* fmt
, ...);
5 // Is -property option specified?
6 enum enforceProperty
= !__traits(compiles
, {
7 int prop(){ return 1; }
11 /*******************************************/
13 template select(alias v1
, alias v2
)
15 static if (enforceProperty
)
28 ref foo(){ getset
= 1; return value
; }
30 enum result
= select
!(0, 1);
31 // -property test.d(xx): Error: not a property foo
32 // (no option) prints "getter"
36 ref foo(int x
){ getset
= 2; value
= x
; return value
; }
38 enum result
= select
!(0, 2);
39 // -property test.d(xx): Error: not a property foo
40 // (no option) prints "setter"
44 @property ref foo(){ getset
= 1; return value
; }
46 enum result
= select
!(1, 1);
47 // -property prints "getter"
48 // (no option) prints "getter"
52 @property ref foo(int x
){ getset
= 2; value
= x
; return value
; }
54 enum result
= select
!(2, 2);
55 // -property prints "setter"
56 // (no option) prints "setter"
62 ref foo() { getset
= 1; return value
; }
63 ref foo(int x
){ getset
= 2; value
= x
; return value
; }
65 enum result
= select
!(0, 2);
66 // -property test.d(xx): Error: not a property foo
67 // (no option) prints "setter"
71 @property ref foo() { getset
= 1; return value
; }
72 ref foo(int x
){ getset
= 2; value
= x
; return value
; }
74 enum result
= select
!(0, 0);
75 // -property test.d(xx): Error: cannot overload both property and non-property functions
76 // (no option) test.d(xx): Error: cannot overload both property and non-property functions
80 ref foo() { getset
= 1; return value
; }
81 @property ref foo(int x
){ getset
= 2; value
= x
; return value
; }
83 enum result
= select
!(0, 0);
84 // -property test.d(xx): Error: cannot overload both property and non-property functions
85 // (no option) test.d(xx): Error: cannot overload both property and non-property functions
89 @property ref foo() { getset
= 1; return value
; }
90 @property ref foo(int x
){ getset
= 2; value
= x
; return value
; }
92 enum result
= select
!(2, 2);
93 // -property prints "setter"
94 // (no option) prints "setter"
102 template iota(int begin
, int end
)
105 static if (begin
== end
)
108 alias seq
!(begin
, iota
!(begin
+1, end
)) iota
;
113 foreach (N
; iota
!(0, 8))
118 static if (Test
!N
.result
== 0)
120 static assert(!is(typeof({ s
.foo
= 1; })));
121 printf("compile error\n");
130 assert(s
.getset
== Test
!N
.result
);
135 /*******************************************/
139 void spam7722(Foo7722 f
) {}
143 auto f
= new Foo7722
;
144 static if (enforceProperty
)
145 static assert(!__traits(compiles
, f
.spam7722
));
150 /*******************************************/
152 @property void check(alias v1
, alias v2
, alias dg
)()
154 void checkImpl(alias v
)()
157 static assert(!__traits(compiles
, dg(0)));
162 static if (enforceProperty
)
170 int foo(int n
) { return 1; }
171 int foo(int n
, int m
) { return 2; }
172 int goo(int[] a
) { return 1; }
173 int goo(int[] a
, int m
) { return 2; }
174 int bar(S s
) { return 1; }
175 int bar(S s
, int n
) { return 2; }
177 int baz(X
)(X x
) { return 1; }
178 int baz(X
)(X x
, int n
) { return 2; }
181 ref int boo(int n
) { return temp
; }
182 ref int coo(int[] a
) { return temp
; }
183 ref int mar(S s
) { return temp
; }
185 ref int maz(X
)(X x
) { return temp
; }
193 check
!(1, 1, x
=> foo(4) ); check
!(1, 1, x
=> baz(4) );
194 check
!(1, 1, x
=> 4.foo() ); check
!(1, 1, x
=> 4.baz() );
195 check
!(0, 1, x
=> 4.foo
); check
!(0, 1, x
=> 4.baz
);
196 check
!(2, 2, x
=> foo(4, 2) ); check
!(2, 2, x
=> baz(4, 2) );
197 check
!(2, 2, x
=> 4.foo(2) ); check
!(2, 2, x
=> 4.baz(2) );
198 check
!(0, 2, x
=> (4.foo
= 2) ); check
!(0, 2, x
=> (4.baz
= 2) );
200 check
!(1, 1, x
=> goo(a
) ); check
!(1, 1, x
=> baz(a
) );
201 check
!(1, 1, x
=> a
.goo() ); check
!(1, 1, x
=> a
.baz() );
202 check
!(0, 1, x
=> a
.goo
); check
!(0, 1, x
=> a
.baz
);
203 check
!(2, 2, x
=> goo(a
, 2) ); check
!(2, 2, x
=> baz(a
, 2) );
204 check
!(2, 2, x
=> a
.goo(2) ); check
!(2, 2, x
=> a
.baz(2) );
205 check
!(0, 2, x
=> (a
.goo
= 2) ); check
!(0, 2, x
=> (a
.baz
= 2) );
207 check
!(1, 1, x
=> bar(s
) ); check
!(1, 1, x
=> baz(s
) );
208 check
!(1, 1, x
=> s
.bar() ); check
!(1, 1, x
=> s
.baz() );
209 check
!(0, 1, x
=> s
.bar
); check
!(0, 1, x
=> s
.baz
);
210 check
!(2, 2, x
=> bar(s
, 2) ); check
!(2, 2, x
=> baz(s
, 2) );
211 check
!(2, 2, x
=> s
.bar(2) ); check
!(2, 2, x
=> s
.baz(2) );
212 check
!(0, 2, x
=> (s
.bar
= 2) ); check
!(0, 2, x
=> (s
.baz
= 2) );
214 check
!(2, 2, x
=> ( boo(4) = 2)); check
!(2, 2, x
=> ( maz(4) = 2));
215 check
!(0, 2, x
=> (4.boo
= 2)); check
!(0, 2, x
=> (4.maz
= 2));
216 check
!(2, 2, x
=> ( coo(a
) = 2)); check
!(2, 2, x
=> ( maz(a
) = 2));
217 check
!(0, 2, x
=> (a
.coo
= 2)); check
!(0, 2, x
=> (a
.maz
= 2));
218 check
!(2, 2, x
=> ( mar(s
) = 2)); check
!(2, 2, x
=> ( maz(s
) = 2));
219 check
!(0, 2, x
=> (s
.mar
= 2)); check
!(0, 2, x
=> (s
.maz
= 2));
222 int hoo(T
)(int n
) { return 1; }
223 int hoo(T
)(int n
, int m
) { return 2; }
224 int koo(T
)(int[] a
) { return 1; }
225 int koo(T
)(int[] a
, int m
) { return 2; }
226 int var(T
)(S s
) { return 1; }
227 int var(T
)(S s
, int n
) { return 2; }
229 int vaz(T
, X
)(X x
) { return 1; }
230 int vaz(T
, X
)(X x
, int n
) { return 2; }
233 ref int voo(T
)(int n
) { return temp
; }
234 ref int woo(T
)(int[] a
) { return temp
; }
235 ref int nar(T
)(S s
) { return temp
; }
237 ref int naz(T
, X
)(X x
) { return temp
; }
245 check
!(1, 1, x
=> hoo
!int(4) ); check
!(1, 1, x
=> vaz
!int(4) );
246 check
!(1, 1, x
=> 4.hoo
!int() ); check
!(1, 1, x
=> 4.vaz
!int() );
247 check
!(0, 1, x
=> 4.hoo
!int ); check
!(0, 1, x
=> 4.vaz
!int );
248 check
!(2, 2, x
=> hoo
!int(4, 2) ); check
!(2, 2, x
=> vaz
!int(4, 2) );
249 check
!(2, 2, x
=> 4.hoo
!int(2) ); check
!(2, 2, x
=> 4.vaz
!int(2) );
250 check
!(0, 2, x
=> (4.hoo
!int = 2) ); check
!(0, 2, x
=> (4.vaz
!int = 2) );
252 check
!(1, 1, x
=> koo
!int(a
) ); check
!(1, 1, x
=> vaz
!int(a
) );
253 check
!(1, 1, x
=> a
.koo
!int() ); check
!(1, 1, x
=> a
.vaz
!int() );
254 check
!(0, 1, x
=> a
.koo
!int ); check
!(0, 1, x
=> a
.vaz
!int );
255 check
!(2, 2, x
=> koo
!int(a
, 2) ); check
!(2, 2, x
=> vaz
!int(a
, 2) );
256 check
!(2, 2, x
=> a
.koo
!int(2) ); check
!(2, 2, x
=> a
.vaz
!int(2) );
257 check
!(0, 2, x
=> (a
.koo
!int = 2) ); check
!(0, 2, x
=> (a
.vaz
!int = 2) );
259 check
!(1, 1, x
=> var
!int(s
) ); check
!(1, 1, x
=> vaz
!int(s
) );
260 check
!(1, 1, x
=> s
.var
!int() ); check
!(1, 1, x
=> s
.vaz
!int() );
261 check
!(0, 1, x
=> s
.var
!int ); check
!(0, 1, x
=> s
.vaz
!int );
262 check
!(2, 2, x
=> var
!int(s
, 2) ); check
!(2, 2, x
=> vaz
!int(s
, 2) );
263 check
!(2, 2, x
=> s
.var
!int(2) ); check
!(2, 2, x
=> s
.vaz
!int(2) );
264 check
!(0, 2, x
=> (s
.var
!int = 2) ); check
!(0, 2, x
=> (s
.vaz
!int = 2) );
266 check
!(2, 2, x
=> ( voo
!int(4) = 2)); check
!(2, 2, x
=> ( naz
!int(4) = 2));
267 check
!(0, 2, x
=> (4.voo
!int = 2)); check
!(0, 2, x
=> (4.naz
!int = 2));
268 check
!(2, 2, x
=> ( woo
!int(a
) = 2)); check
!(2, 2, x
=> ( naz
!int(a
) = 2));
269 check
!(0, 2, x
=> (a
.woo
!int = 2)); check
!(0, 2, x
=> (a
.naz
!int = 2));
270 check
!(2, 2, x
=> ( nar
!int(s
) = 2)); check
!(2, 2, x
=> ( naz
!int(s
) = 2));
271 check
!(0, 2, x
=> (s
.nar
!int = 2)); check
!(0, 2, x
=> (s
.naz
!int = 2));
274 /*******************************************/
279 @property bool foo7174() { return true; }
280 static if (foo7174
) {}
283 /***************************************************/
286 @property foo7274(){ return "test"; }
287 @property bar7274(){ return "kernel32.lib"; }
289 pragma(msg
, "decl: ", foo7274
); // print "decl: foo", not "decl: test"
290 version(Windows
) pragma(lib
, bar7274
); // Error: pragma lib string expected for library name, not 'bar'
294 pragma(msg
, "stmt: ", foo7274
); // print "stmt: foo", not "stmt: test"
295 //pragma(lib, bar); // Error: pragma(lib) not allowed as statement
298 /***************************************************/
303 @property int bar1() { return 0; }
304 @property int bar2() { return 1; }
305 @property int bar3() { return 2; }
315 /*****************************************/
322 @property long pr() { return 1; }
323 @property void pr(int) {}
325 @property long a1()() { return 1; }
326 @property void a1()(int) {}
327 template a2() { @property long a2() { return 1; } }
328 template a2() { @property void a2(int) {} }
329 template a3() { long a3() @property { return 1; } }
330 template a3() { void a3(int) @property {} }
334 @property long b1()() { return 1; }
335 @property void b1()(int) {}
336 template b2() { @property long b2() { return 1; } }
337 template b2() { @property void b2(int) {} }
338 template b3() { long b3() @property { return 1; } }
339 template b3() { void b3(int) @property {} }
342 @property long c1(T
)() { return 1; }
343 @property long c1(T
)(int) { return 1; }
344 template c2(T
) { @property long c2() { return 1; } }
345 template c2(T
) { @property void c2(int) {} }
346 template c3(T
) { long c3() @property { return 1; } }
347 template c3(T
) { void c3(int) @property {} }
351 @property long d1(T
)() { return 1; }
352 @property void d1(T
)(int) {}
353 template d2(T
) { @property long d2() { return 1; } }
354 template d2(T
) { @property void d2(int) {} }
355 template d3(T
) { long d3() @property { return 1; } }
356 template d3(T
) { void d3(int) @property {} }
362 static assert(is(typeof(pr
) == long));
365 static assert(is(typeof(b1
) == long));
366 static assert(is(typeof(b2
) == long));
367 static assert(is(typeof(b3
) == long));
370 static assert(is(typeof(d1
!int) == long));
371 static assert(is(typeof(d2
!int) == long));
372 static assert(is(typeof(d3
!int) == long));
378 static assert(is(typeof(p
.pr
) == long));
381 static assert(is(typeof(p
.a1
) == long));
382 static assert(is(typeof(p
.a2
) == long));
383 static assert(is(typeof(p
.a3
) == long));
386 static assert(is(typeof(P
.b1
) == long));
387 static assert(is(typeof(P
.b2
) == long));
388 static assert(is(typeof(P
.b3
) == long));
391 static assert(is(typeof(p
.c1
!int) == long));
392 static assert(is(typeof(p
.c2
!int) == long));
393 static assert(is(typeof(p
.c3
!int) == long));
398 long fn() { return 1; }
401 long a1()() { return 1; }
403 template a2() { long a2() { return 1; } }
404 template a2() { void a2(int) {} }
408 long b1()() { return 1; }
410 template b2() { long b2() { return 1; } }
411 template b2() { void b2(int) {} }
414 long c1(T
)() { return 1; }
415 long c1(T
)(int) { return 1; }
416 template c2(T
) { long c2() { return 1; } }
417 template c2(T
) { void c2(int) {} }
421 long d1(T
)() { return 1; }
423 template d2(T
) { long d2() { return 1; } }
424 template d2(T
) { void d2(int) {} }
430 static assert( is(typeof(fn
) == function));
433 static assert(!is(typeof(b1
) == long));
434 static assert(!is(typeof(b2
) == long));
437 static assert(!is(typeof(d1
!int) == long));
438 static assert(!is(typeof(d2
!int) == long));
444 static assert(is( typeof(f
.fn
) == function));
447 static assert(!is(typeof(f
.a1
) == long));
448 static assert(!is(typeof(f
.a2
) == long));
451 static assert(!is(typeof(F
.b1
) == long));
452 static assert(!is(typeof(F
.b2
) == long));
455 static assert(!is(typeof(f
.c1
!int) == long));
456 static assert(!is(typeof(f
.c2
!int) == long));
460 /*****************************************/
465 static @property int min() { return 123; }
467 @property int T8251_Min() { return 456; }
469 template T8251a (int v
) { int T8251a
= v
; }
471 template T8251b1(int v
= S8251
.min
) { int T8251b1
= v
; }
472 template T8251b2(int v
= T8251_Min
) { int T8251b2
= v
; }
474 template T8251c1(int v
: S8251
.min
) { int T8251c1
= v
; }
475 template T8251c2(int v
: T8251_Min
) { int T8251c2
= v
; }
479 static assert(S8251
.min
== 123); // OK
480 static assert(T8251_Min
== 456); // OK
481 int a0
= T8251a
!(S8251
.min()); // OK
482 int b0
= T8251a
!(T8251_Min()); // OK
484 // TemplateValueParameter
485 int a1
= T8251a
!(S8251
.min
); // NG
486 int b1
= T8251a
!(T8251_Min
); // NG
488 // TemplateValueParameterDefault
489 int a2
= T8251b1
!(); // NG
490 int b2
= T8251b2
!(); // NG
492 // TemplateValueParameterSpecialization
493 int a3
= T8251c1
!(123); // NG
494 int b3
= T8251c2
!(456); // NG
497 /*****************************************/
500 @property bool foo9063(){ return true; }
501 static assert(foo9063
);
503 /*****************************************/
512 struct Foo9234(alias F
) {}
513 struct Foo9234(string thunk
) {}
515 /*****************************************/
518 mixin template Getter10103()
520 @property auto foo() { return v
; }
521 @property auto bar()() { return v
; }
522 @property auto baz(T
)() { return v
; }
524 static @property auto goo() { return 1; }
527 mixin template Setter10103()
529 @property void foo(int x
) { v
= x
; }
530 @property void bar()(int x
) { v
= x
; }
531 @property void baz(T
)(int x
) { v
= x
; }
533 static @property void goo(int x
) {}
539 mixin Getter10103
!();
540 mixin Setter10103
!();
545 auto f
= Foo10103(4);
559 /*****************************************/
562 template OriginalType10197(T
)
564 static if (is(T U
== enum))
565 alias OriginalType10197
= U
;
572 enum E
: int { F
= -20 }
576 @trusted @property T
as(T
)()
577 if (is(T
== int) && !is(T
== enum))
581 @trusted @property T
as(T
)()
584 return cast(T
)as
!(OriginalType10197
!T
);
589 assert(val
.as
!int == -20);
590 assert(val
.as
!E
== E
.F
);
593 /*****************************************/