-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Allow deleting elements from NamedTuple/Hash literals #9837
base: master
Are you sure you want to change the base?
Conversation
This is good for another review. |
Also allow symbols to be used for NamedTupleLiterals
5177b76
to
94ea9e0
Compare
@asterite Done. Also rebased on master to fix that CI issue. |
This is good for another review. |
Bump. |
@oprypin Bump :) |
Does #7109 (comment) not apply here? |
@HertzDevil I'm not sure. IMO it makes sense to have this given you can construct a hash entirely within macro land, but then if you want to remove a key from it, you can't and would have rebuild the whole hash. So it's not like you cant mutate a hash at the moment, it's just incomplete. That's my usecase at least, copying the named arguments from an annotation, processing it (i.e. using the provided values to add/remove arguments), then double splat it into the constructor of a struct. |
@Blacksmoke16 I'm not sure what you mean. Maybe it makes sense, but the argument against deleting from a Hash is exactly the same as about deleting from an Array (the linked comment) |
@oprypin I don't see it that way. The way I took it the linked comment's argument is against mutations because it makes tracking dependency order harder. I.e. using the old mutable constant DSL pattern before annotations became more prevalent. However after working a lot more with macros since that original issue; I don't think that argument is entirely correct mainly because there are use cases for mutating data structures other than as a means of "registering" things. This is even more important if/when #8835 is ever implemented, as it's easy to see hashes/arrays being passed that you'd expect to be able to modify. I also don't really see the benefit of removing mutating methods from these macro literals anyway. It just seems like it's making them less useful for no reason. EDIT: I do agree that there are features that could be implemented as a better/easier alternative, e.g. #9802, but removing these methods still seems kinda arbitrary. |
Bump, ran into this again. I have an annotation like struct CustomTag < ADI::AbstractTag
getter value : Int32
def initialize(@value : Int32, name : String, priority : Int32? = nil, *, tag_type = nil)
super name, priority
end
end Of which I'm creating it via |
IMO it makes more sense to have (I would personally avoid this call and |
@HertzDevil Not as elegant but that would work too I suppose. Better than nothing.
That's a bit easier said than done I think because the instantiation of the struct is still in the macro context. If it wasn't then you could easily use a EDIT: Looks like you could do |
Resolves #8849