Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue 6400 - Better interaction between with() and opDispatch (Pa…
…rt 2)
- Loading branch information
Showing
3 changed files
with
72 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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; | ||
} |