-
-
Notifications
You must be signed in to change notification settings - Fork 608
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
071de77
commit 75f6f32
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
compiler/test/fail_compilation/interpolatedexpressionsequence_postfix.d
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,13 @@ | ||
| /* TEST_OUTPUT: | ||
| --- | ||
| interpolatedexpressionsequence_postfix.d(10): Error: String postfixes on interpolated expression sequences are not allowed. | ||
| interpolatedexpressionsequence_postfix.d(11): Error: String postfixes on interpolated expression sequences are not allowed. | ||
| interpolatedexpressionsequence_postfix.d(12): Error: String postfixes on interpolated expression sequences are not allowed. | ||
| --- | ||
| */ | ||
| void main() { | ||
| // all postfixes are banned | ||
| auto c = i"foo"c; | ||
| auto w = i"foo"w; | ||
| auto d = i"foo"d; | ||
| } |
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,38 @@ | ||
| import core.interpolation; | ||
|
|
||
| alias AliasSeq(T...) = T; | ||
|
|
||
| void main() { | ||
| int a = 1; | ||
| string b = "one"; | ||
| // parser won't permit alias = i".." directly; i"..." is meant to | ||
| // be used as a function/template parameter at this time. | ||
| alias expr = AliasSeq!i"$a $(b)"; | ||
| // elements from the source code are available at compile time, so | ||
| // we static assert those, but the values, of course, are different | ||
| static assert(expr[0] == InterpolationHeader()); | ||
| static assert(expr[1] == InterpolatedExpression!"a"()); | ||
| assert(expr[2] == a); // actual value not available at compile time | ||
| static assert(expr[3] == InterpolatedLiteral!" "()); | ||
| // the parens around the expression are not included | ||
| static assert(expr[4] == InterpolatedExpression!"b"()); | ||
| assert(expr[5] == b); // actual value not available at compile time | ||
| static assert(expr[6] == InterpolationFooter()); | ||
|
|
||
| // it does currently allow `auto` to be used, it creates a value tuple | ||
| // you can embed any D expressions inside the parenthesis, and the | ||
| // token is not ended until you get the *outer* ) and ". | ||
| auto thing = i"$b $("$" ~ ')' ~ `"`)"; | ||
| string s; | ||
| foreach(item; thing) | ||
| // all the items provided by core.interpolation have | ||
| // toString to return an appropriate value | ||
| // | ||
| // then this particular example only has embedded strings | ||
| // and chars, to we can append them directly | ||
| static if(__traits(hasMember, item, "toString")) | ||
| s ~= item.toString(); | ||
| else | ||
| s ~= item; | ||
| assert(s == "one $)\""); | ||
| } |