-
-
Notifications
You must be signed in to change notification settings - Fork 608
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 __traits(getLocation)
#10013
Add __traits(getLocation)
#10013
Conversation
2e27606
to
a3551ad
Compare
Oh wow, perfect. Thanks!! |
No probs, you're writing the test suite for it though! Specifically all the cases that look like symbols but actually end up as something else e.g. |
And things like overload sets. |
src/dmd/traits.d
Outdated
} | ||
|
||
auto exps = new Expressions(3); | ||
exps.data[0] = new StringExp(e.loc, cast(char*)s.loc.filename); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the void*,size_t overload.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should the string be mem.xdup
'ed too? I wasn't sure if e.g. ctfe screws with the contents.
09305f9
to
ef2c455
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Would be nice to have a test that tests all elements returned and not just first one
- Needs a changelog as well.
ef2c455
to
94befcc
Compare
7431d90
to
6a699d8
Compare
changelog added, test for line and column added
f8abd3a
to
64b5c56
Compare
Thanks for your pull request and interest in making D better, @thewilsonator! 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 fetch digger
dub run digger -- build "master + dmd#10013" |
64b5c56
to
4239047
Compare
560e48b
to
258477f
Compare
258477f
to
40a09fe
Compare
@@ -4,6 +4,7 @@ | |||
// effort to keep the number of files in the `compilable` folder to a minimum. | |||
|
|||
// https://issues.dlang.org/show_bug.cgi?id=19152 | |||
module traits; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if the module name is not explicitly specified? I would expect the module name to be inferred from the file name and things to just work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so, this was just out of habit to add a module declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked, you get verbatim what was passed on the command line .././../foo/./../file.d
and all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking, indeed we should use an explicit module name here in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add handling of overloads. A mention in the changelog is not enough and will be forgotten soon.
Test case accompanying the suggested changes:
module trait_loc_ov_err;
/*
TEST_OUTPUT:
---
fail_compilation/trait_loc_ov_err.d(25): Error: cannot get location of an overload set, use `__traits(getOverloads, ..., "ov1")[N]` to get the Nth overload location
fail_compilation/trait_loc_ov_err.d(26): Error: cannot get location of an overload set, use `__traits(getOverloads, ..., "ov2")[N]` to get the Nth overload location
fail_compilation/trait_loc_ov_err.d(27): Error: cannot get location of an overload set, use `__traits(getOverloads, ..., "OvT(T)")[N]` to get the Nth overload location
---
*/
void ov1(){}
void ov1(int){}
void ov21(){}
void ov22(int){}
alias ov2 = ov21;
alias ov2 = ov22;
template OvT(T){}
template OvT(T, U){}
enum e1 = __traits(getLocation, ov1);
enum e2 = __traits(getLocation, ov2);
enum e3 = __traits(getLocation, OvT);
Done. |
Hmm, so
will always give an error because it seems that using templates with I'm tempted to just define it to always return the first overload of the set, or even just add an integer option to select which overload as part of the trait. Any thoughts, ideas, opinions? |
Yes, my suggestion would be to comment the handling of |
@thewilsonator : abandoning the detection of template overloads is the way to go. |
Its impossible to tell it the user has used `__traits(getOverloads,…,true)`
Finally got around to it. |
is this in the new release? looks like no... |
No it did not make the cut. |
Hi, that is amazing and super useful. Could we also get a simple wrapper in |
https://forum.dlang.org/thread/mailman.9439.1560115627.29801.digitalmars-d@puremagic.com