-
-
Notifications
You must be signed in to change notification settings - Fork 607
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 #7576
Conversation
Thanks for your pull request, @wilzbach! 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#7576" |
9ad1931
to
2600eaf
Compare
Jenkins failure looks unrelated: dlang/ci#105 |
{ | ||
this.storageClass = storageClass; | ||
this.type = type; | ||
this.ident = ident; | ||
this.defaultArg = defaultArg; | ||
this.userAttribDecl = userAttribDecl; |
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.
@RazvanN7 do you have any plans on removing the giant code duplication in astbase
?
Will this work for template parameters? |
Not this version. |
|
||
void wrongAttr1(@safe int); | ||
void wrongAttr2(@safe void function()); | ||
void wrongAttr3(@safe void delegate()); |
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.
That isn't going to be confusing at all :D
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.
Those are invalid attributes, so it shouldn't be too big of a problem.
test/runnable/uda.d
Outdated
} | ||
|
||
/************************************************/ | ||
|
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.
Probably could use a test with a tuple as well
@wilzbach that do you mean with "template d parameters"? |
|
||
extern (D) alias ForeachDg = int delegate(size_t idx, Parameter param); | ||
|
||
final extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg) | ||
final extern (D) this(StorageClass storageClass, Type type, Identifier ident, Expression defaultArg, UserAttributeDeclaration userAttribDecl) |
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.
Expression defaultArg, UserAttributeDeclaration userAttribDecl = null)
Giving this a default value would save on a lot of code edits that just add a null as the last parameter. Not sure if default values are being avoided here on purpose or not.
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.
AFAICT is the prevalent coding style in the DMD source code to prefer explicitness.
I'm trying to get a hold on the scope of this PR. auto a(int x)(void function(@(x) int) f);
auto b = a((@(2) int){ }); |
@John-Colvin |
fb14fa9
to
d1b5b2d
Compare
d1b5b2d
to
39718f6
Compare
39718f6
to
9b621d6
Compare
4679f23
to
1656137
Compare
Finally got around submitting the dlang.org PR: dlang/dlang.org#2363 |
static assert(is(ParameterUDA!(3, test14x)[0] == Test14UDA4!"3")); | ||
} | ||
|
||
void test15x(@(20) void delegate(int) @safe dg) |
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 about the parameters on delegates, are UDAs on those supported? Either way I think it's worth having a test case, showing either that it works or that it doesn't 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.
Added the tests below.
Ping. What status of that? |
I asked for some more tests, which I don't think has been added. Not sure what else. @wilzbach ping. |
3a69876
to
c012027
Compare
Sorry. I haven't found much time for this, but now managed to add these tests. See
Same here. |
{ | ||
static assert([__traits(getAttributes, a)] == [22]); | ||
} | ||
--- |
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.
Perhaps include an example of how to get the UDAs of a parameter from outside of a function. Or should that be left as an exercise for the reader 😃.
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.
That's a bit more complicated and I think we will provide an interface in std.traits
anyhow.
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.
Tests for the following could be added:
|
c012027
to
0ef6f63
Compare
Only the latter was supported (i.e. with parentheses). I added support for
Added to
That's not supported as of now. I'm not sure it's that useful, but if people run into use cases for it, it could always be added? |
I’m not asking for adding new functionality, just to add tests that shows it’s either compiles or fails to compile. |
Cool. I wonder if Andrei will have use of this in his complexity library... I notified him and he answered that this PR indeed will make it more powerful! |
#4783 revived from the dead.
See dlang/DIPs#105 for a respective DIP.
Official spelling is "user-defined attributes".