-
-
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.
Move issue 7815 case to fail_compilation, because it was invalid
It was wrongly accepted by the bug in `StaticIfCondition::include()`.
Bug explanation copied from fail_compilation/fail7815.d:
----
When the Move struct member is analyzed:
1. mixin Helpers!() is instantiated.
2. In Helpers!(), static if and its condition is(Flags!Move)) evaluated.
3. In Flags!Move, string mixin evaluates and CTFE lambda.
4. __traits(derivedMembers, Move) tries to see the member of Move.
4a. mixin Helpers!() member is analyzed.
4b. `static if (is(Flags!Move))` in Helpers!() is evaluated
4c. The Flags!Move instantiation is already in progress, so it cannot be resolved.
4d. `static if` fails because Flags!Move cannot be determined as a type.
5. __traits(derivedMembers, Move) returns a 1-length tuple("a").
6. The lambda in Flags!Move returns a string "struct Flags {...}", then
Flags!Move is instantiated to a new struct Flags.
7. Finally Move struct does not have flags member, then the `enum a7815`
definition will fail in its initializer.- Loading branch information
Showing
3 changed files
with
70 additions
and
35 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 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,65 @@ | ||
| // REQUIRED_ARGS: -o- | ||
| /* | ||
| TEST_OUTPUT: | ||
| --- | ||
| X: tuple("x") | ||
| fail_compilation/fail7815.d(47): Error: no property 'flags' for type 'Move' | ||
| --- | ||
| */ | ||
|
|
||
| mixin template Helpers() | ||
| { | ||
| static if (is(Flags!Move)) | ||
| { | ||
| Flags!Move flags; | ||
| } | ||
| else | ||
| { | ||
| pragma(msg, "X: ", __traits(derivedMembers, Flags!Move)); | ||
| } | ||
| } | ||
|
|
||
| template Flags(T) | ||
| { | ||
| mixin({ | ||
| int defs = 1; | ||
| foreach (name; __traits(derivedMembers, Move)) | ||
| { | ||
| defs++; | ||
| } | ||
| if (defs) | ||
| { | ||
| return "struct Flags { bool x; }"; | ||
| } | ||
| else | ||
| { | ||
| return ""; | ||
| } | ||
| }()); | ||
| } | ||
|
|
||
| struct Move | ||
| { | ||
| int a; | ||
| mixin Helpers!(); | ||
| } | ||
|
|
||
| enum a7815 = Move.init.flags; | ||
|
|
||
| /+ | ||
| This is an invalid case. | ||
| When the Move struct member is analyzed: | ||
| 1. mixin Helpers!() is instantiated. | ||
| 2. In Helpers!(), static if and its condition is(Flags!Move)) evaluated. | ||
| 3. In Flags!Move, string mixin evaluates and CTFE lambda. | ||
| 4. __traits(derivedMembers, Move) tries to see the member of Move. | ||
| 4a. mixin Helpers!() member is analyzed. | ||
| 4b. `static if (is(Flags!Move))` in Helpers!() is evaluated | ||
| 4c. The Flags!Move instantiation is already in progress, so it cannot be resolved. | ||
| 4d. `static if` fails because Flags!Move cannot be determined as a type. | ||
| 5. __traits(derivedMembers, Move) returns a 1-length tuple("a"). | ||
| 6. The lambda in Flags!Move returns a string "struct Flags {...}", then | ||
| Flags!Move is instantiated to a new struct Flags. | ||
| 7. Finally Move struct does not have flags member, then the `enum a7815` | ||
| definition will fail in its initializer. | ||
| +/ |
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