-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
at-kwdef support for parametric types and subtypes #29316
Conversation
I have no idea what is happening, but I get this locally:
any ideas? |
Seems like another manifestation of #28808. There is already one workaround at julia/contrib/generate_precompile.jl Line 165 in 2fd386c
|
Adding this makes it compile: I was not aware that
Also, here some tests, adapted from Parameters.jl, which might be good to add: https://gist.github.com/mauro3/6a700f5b6fe09b4d0c130c354a8178ac. (although, I did not check which ones are redundant with the already existing ones). |
Thanks for the fix and the examples. I'm not sure what you mean by "feature completeness", but if it exists, it might as well be correct. |
Sorry, with "feature complete" I meant what the equivalent macro How about adding to the docs something like: "If inner constructors are defined, then |
Makes sense: what else is missing compared with How about:
|
Four bits which are "missing" are:
I don't think the first three are suitable for Base. The last would be nice though, but maybe for another PR.
|
Wait, there is another useful one:
x-ref: #5333 |
I can see that last one would be useful, but there is the question of what to do if the struct takes a single field. e.g.
then what should
give? |
4891396
to
28d8f98
Compare
Just |
How would you construct the nested type? |
It's a pity we can't overload splatting, then we could use the syntax
At the moment that would require writing an iterator over the object. |
I see the problem. But you already figured out the solution:
but you should probably implement that in a separate PR. ;-) No, more seriously, probably leave that feature for now. Alternatively, just forget about the nested type in the one-field case. |
Okay, I think this is ready to merge. |
LGTM except the doc-string update: Inner constructors can still be defined, but one needs to accept arguments in the same form as the default inner constructor (i.e. one positional argument per field) in order to function correctly with the keyword outer constructor. |
Done. |
So this will be in 1.1, right? |
Yes, though it shouldn't be breaking, so we could backport if you wanted it? |
Features don't go in point releases. |
(at-kwdef for parametric structs, and structs with supertypes).
(at-kwdef for parametric structs, and structs with supertypes).
(at-kwdef for parametric structs, and structs with supertypes).
(at-kwdef for parametric structs, and structs with supertypes).
(at-kwdef for parametric structs, and structs with supertypes).
(at-kwdef for parametric structs, and structs with supertypes).
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
Addition of NEWS and compat admonitions for important changes between Julia 1.0 and 1.1, including: - Custom .css-style for compat admonitions. - Information about compat annotations to CONTRIBUTING.md. - NEWS.md entry for PRs #30090, #30035, #30022, #29978, #29969, #29858, #29845, #29754, #29638, #29636, #29615, #29600, #29506, #29469, #29316, #29259, #29178, #29153, #29033, #28902, #28761, #28745, #28708, #28696, #29997, #28790, #29092, #29108, #29782 - Compat annotation for PRs #30090, #30013, #29978, #29890, #29858, #29827, #29754, #29679, #29636, #29623, #29600, #29440, #29316, #29259, #29178, #29157, #29153, #29033, #28902, #28878, #28761, #28708, #28156, #29733, #29670, #29997, #28790, #29092, #29108, #29782, #25278 - Documentation for broadcasting CartesianIndices (#30230). - Documentation for Base.julia_cmd(). - Documentation for colon constructor of CartesianIndices (#29440). - Documentation for ^(::Matrix, ::Number) and ^(::Number, ::Matrix). - Run NEWS-update.jl. Co-authored-by: Morten Piibeleht <morten.piibeleht@gmail.com> Co-authored-by: Fredrik Ekre <ekrefredrik@gmail.com>
I would argue this is a bugfix rather than a feature. (from https://discourse.julialang.org/t/kwdef-not-working-for-parametric-struct/25286/4) |
It's not even exported. |
Fixes #29307.