-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
UDAs for function arguments #4783
Conversation
|
|
||
| void test13() | ||
| { | ||
| static if (is(typeof(test12x) PT == __parameters)) |
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.
test12x vs test13x?
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.
Omg, this test was totally wrong. Fixed.
|
I'm afraid I don't understand that Urgh... After some searching I found this: |
0c59983 to
eebe354
Compare
Yes, You should write |
|
Having to emulate UDAs on parameters is doable, although it's a pain. I'd really like to have something in the language to support it (as long as it doesn't conflict with other features / grammar), but Having a magical tuple that can hold things not expressible in any other part of the language (and that vanishes as soon as you put them through a tuple) is already bad enough, please, don't put more magic in it. |
|
I think it's important to note that D can currently introduce new storage classes without breaking any code, due to the fact that UDAs on parameters are not allowed. This pull request would make that no longer true. For example, we could add a new storage class today and be confident that no code would be broken: Although I doubt that is much of a concern at this point. |
Yes, current
The same point for global UDAs. However, when |
|
@IgorStepanov Additionally you need to tweak enum uda;
void foo(@uda int v) {}
alias x = X!(typeof(foo));
template X(F) {
// in here, the function type F must not have any udas.
} |
eebe354 to
8f7d239
Compare
|
@9rnsr Done. Also I've added the corresponding test. |
Git repository corruption I think. Fixed for now, hopefully it won't recur |
|
@9rnsr Any other objections?
Thanks. |
| if (stc == STCproperty || stc == STCnogc || stc == STCdisable || | ||
| stc == STCsafe || stc == STCtrusted || stc == STCsystem) | ||
| { | ||
| error("@%s attribute for function argument is not supported", token.toChars()); |
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.
Better wording: s/argument/parameter/
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.
fixed
|
Excepting nitpicks for the diagnostic messages, the implementation looks good to me. |
8f7d239 to
9be0e59
Compare
I've fixed messages. Thanks! |
My point was that as soon as it's introduced, we'll have to support it (unless it doesn't make it into a release). But since this would ease my life a lot, I won't complain too much :-) Is there a corresponding documentation change open ? Also, any chance you can add a test for the following scenarios:
|
9be0e59 to
2e0b54f
Compare
We will use phobos wrapper template in high-level code. Similar to
Yes, done.
See
See Any other ideas?
It is not made. But I'll do it. |
|
@9rnsr I've changed |
2e0b54f to
3dc677c
Compare
|
@9rnsr Please, revalidate this. I've added two changes, declared in previous post. |
|
|
||
| if (token.value == TOKdotdotdot) | ||
| error("variadic parameter cannot has UDAs"); |
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.
s/cannot has/cannot have/
|
Looks good excepting one diagnostic nitpick. |
| TEST_OUTPUT: | ||
| --- | ||
| fail_compilation/udaparams.d(15): Error: variadic parameter cannot has UDAs | ||
| fail_compilation/udaparams.d(16): Error: variadic parameter cannot has UDAs |
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.
This is inconsistent with the error message on the very next line, which uses user defined attributes as opposed to UDAs. You should use either one or the other, but not both.
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.
Ok, will change to "user defined attributes".
|
What's the status on this? |
|
Revived in #7576 |
Implementation of subj.
This topic was partially discussed ~year ago in NG.
The general idea:
This feature is very usefull for different bindings generators like Web MVC or REST bindings like Java Spring MVC.