-
-
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
Incorrect scope after including **::Serializable #6194
Comments
this is because exist annotation class Foo
include JSON::Serializable
include ::Options
end |
Yeah I knew that would fix it too, forgot to mention. I guess I didn't realize that annotations come along with |
Feels to me like we shouldn't be including stuff into people's classes when they include Perhaps a rename to |
@RX14 I'd question if annotations should be included into other namespaces at all...? I can't think of a use case for this. |
But yes, removing
|
Well, if annotations would have been named (however, it of course can happen with any other type, not just annotations) Just learn to live with these deficiencies of the language, they are not a big deal. |
Yes, this is just as any other modules conflicts. I think this is ok, and not even related to annotations, it happens from time to time. |
@straight-shoota |
How about we put |
this would look weird: struct A
include JSON::Serializable
include JSON::Serialization::Unmapped
@a : Int32
end |
Think about all the people wanting to include both Serializable and a custom module named Options or Unmapped. The count will be maybe just two or three people in the universe. I think it's better those two or three add a full path there, instead of redesigning the API and ruin it for everyone else (including those two or three). |
I neither there is much to do here. @straight-shoota if a module is used for namespaces lots of annotation you want them to be included in the namespace to avoid repetition of the full path. As @RX14 pointed out is a side effect of including Whatever other nice name we choose for |
this is worse conflict, btw: record Link, before : String?, href : String?, anchor : String?, after : String?
|
Vote to make annotation names end with a mandatory Annotation suffix? 👍 |
may be Annotation suffix not bad, because defining annotations expect to be quite rare. |
And also, their usage is only inside |
@asterite |
@Sija What about The first PR I sent with annotations was about having: module Moo
annotation FooAnnotation
end
end And using it like: @[Moo::Foo] And retrieving in macros with: type.get_annotation(Moo::FooAnnotation) Since annotations are usually created by the same ones consuming them (like And this is proven to work, it's how C# implements it (kind of). I'll just leave this idea here. You can discuss other alternatives, and eventually do a change if it's needed 👍 |
What about |
I still don't like it because it's magic and a hack. If we're going to jump through all these hoops, why not actually have a separate namespace for annotations. And implementing this doesn't solve the problem, because |
The weird part of Annotation suffix is that either a) the declaration is or b) the declaration is I'm ok with going through option b. The only one that should care about that is the developer coding the effect of the annotation. So it's easy to point in the documentation/guide. It helps for better annotation name that won't clash with other constants. |
I think a is better. It's how it's done in C# |
I guess as long as it is used as |
(a) it's like it's done in C# because they are classes. But here they word annotation is already stated. That is way I am more in favor of (b). I am not against (a) though. The whole thing is reducing the clashing which both do. |
I actually think the current behaviour is fine. It's no use to open an issue and complain about every little detail in the language. The solution was given (use |
@asterite I disagree IMO the annotations should not be part of the user-accessible type system. |
Given:
Yields:
Compiles if
Serializable
is included last (or ifOptions
is renamed to something not taken):Not fully sure of the scope of the issue (is it with annotations?
macro included
?), this is just the case I ran into this with.The text was updated successfully, but these errors were encountered: