-
-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for version as expression #20788
base: master
Are you sure you want to change the base?
Add support for version as expression #20788
Conversation
Thanks for your pull request and interest in making D better, @bangbangsheshotmedown! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#20788" |
i don't understand, the code compiles on my machine And i also realize that this will not work since it's not done parsing, perhaps someone can help |
The parser is standalone, not dependent on dmd's semantic code. It is templated and can be instantiated both with DMD's AST (with extra semantic info), or 'astbase', a parser only version of the AST. Your code tries to access semantic info The duplicated astbase.d module is rather ugly and work is being done to remove it by refactoring dmd's ast to be separate from semantic routines (https://github.com/orgs/dlang/projects/41), but even so, the implementation of this feature should probably not try to resolve the The proper implementation solution is to create a new Expression node similar to the |
Thanks for the detailled explanation, i'll rework this PR
Well, i disagree with that Nobody will convince me that this is good: version(linux)
{
enum value = 42;
}
else
{
enum value = 0;
} |
Has this been approved ? @WalterBright has been consistently against it. |
What problem are you trying to solve? |
The example in the change log entry is self explanatory, makes simple cases easier to process 8 lines of code vs just 1 Right now i solve it with: struct Version
{
static bool opDispatch(string identifier)()
{
mixin("
version(", identifier, ")
return true;
else
return false;
");
}
} This however feels like over-engineering for something that should be simple, and i am not a fan of having to import a module, i never remember wich file has this code and let's be honest, an import for this is cringe |
That's the only thing i miss from C, having to include my utility file only once Perhaps D could have something like C#'s This would solve my issue |
That does not work. The change is sold as an expression but if so you have to support void v(T)(T t);
void main()
{
v!int(version(linux) ? 42 : 0);
} such a feature requires much more work. |
D is healing