blob: 8b1018400f2bdbf19679416822dd67708dbc4bf0 (
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
|
/* TEST_OUTPUT:
---
Foo
Bar
Foo
Bar
Bar
Foo
Bar
---
*/
// https://issues.dlang.org/show_bug.cgi?id=6400
enum int base(string name) = 10 * (name[$-1] - '0');
struct Foo { int opDispatch(string name)() { pragma(msg, "Foo"); return base!name + 1; } }
struct Bar { int opDispatch(string name)() { pragma(msg, "Bar"); return base!name + 2; } }
struct Baz { }
void main()
{
assert(test());
static assert(test());
}
bool test()
{
auto foo = new Foo;
auto bar = new Bar;
auto baz = new Baz;
with (foo)
{
assert(f1() == 11);
with (baz) assert(f1() == 11);
with (bar)
{
assert(f2() == 22);
with (baz) assert(f2() == 22);
with (foo)
{
assert(f3() == 31);
with (baz) assert(f3() == 31);
with (bar)
{
assert(f4() == 42);
with (baz) assert(f4() == 42);
with (baz)
{
assert(f5() == 52);
with (baz) assert(f5() == 52);
}
with (foo)
{
assert(f6() == 61);
with (baz) assert(f6() == 61);
}
with (bar)
{
assert(f7() == 72);
with (baz) assert(f7() == 72);
}
}
}
}
}
return true;
}
|