Debian Codegraph @

gcc/testsuite/gdc.test/runnable/b6400.d

raw
1 /* TEST_OUTPUT:
2 ---
3 Foo
4 Bar
5 Foo
6 Bar
7 Bar
8 Foo
9 Bar
10 ---
11 */
12
13 // https://issues.dlang.org/show_bug.cgi?id=6400
14
15 enum int base(string name) = 10 * (name[$-1] - '0');
16 struct Foo { int opDispatch(string name)() { pragma(msg, "Foo"); return base!name + 1; } }
17 struct Bar { int opDispatch(string name)() { pragma(msg, "Bar"); return base!name + 2; } }
18 struct Baz { }
19
20 void main()
21 {
22 assert(test());
23 static assert(test());
24 }
25
26 bool test()
27 {
28 auto foo = new Foo;
29 auto bar = new Bar;
30 auto baz = new Baz;
31
32 with (foo)
33 {
34 assert(f1() == 11);
35 with (baz) assert(f1() == 11);
36 with (bar)
37 {
38 assert(f2() == 22);
39 with (baz) assert(f2() == 22);
40 with (foo)
41 {
42 assert(f3() == 31);
43 with (baz) assert(f3() == 31);
44 with (bar)
45 {
46 assert(f4() == 42);
47 with (baz) assert(f4() == 42);
48 with (baz)
49 {
50 assert(f5() == 52);
51 with (baz) assert(f5() == 52);
52 }
53 with (foo)
54 {
55 assert(f6() == 61);
56 with (baz) assert(f6() == 61);
57 }
58 with (bar)
59 {
60 assert(f7() == 72);
61 with (baz) assert(f7() == 72);
62 }
63 }
64 }
65 }
66 }
67
68 return true;
69 }