-
-
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
User-defined annotations #6063
Merged
Merged
User-defined annotations #6063
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
d6f1c61
User-defined annotations
asterite 96a658d
Don't require annotations to end with "Annotation"
asterite 1d793af
Add TODO about the hardcoded annotation rules
asterite 8cd1ad0
Don't change enum docs for now
asterite b223a17
Use "annotation" suffix for Program variables that represent annotations
asterite c3eb6d2
Annotations: add spec for overriding an annotation usage
asterite c3e6c04
Test non-existent annotations, or wrong usage of annotation
asterite 4413d66
Error if using annotation other than ThreadLocal for class vars
asterite 39e577d
Give error when using invalid annotation on defs or funs
asterite 6abcc25
Don't carry annotations from lib to fun
asterite b56d76b
Clear annotations before processing inner type.
asterite 1009e07
Typo: remove incorrect plural
asterite 5aedf7b
Refactor macro method "annotation" implementation
asterite 4da09a2
Mark macro method helper as private
asterite e6a6a1e
Allow annotations on methods
asterite 615adac
In macros, `annotation` nests
asterite File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -419,18 +419,27 @@ abstract class Crystal::SemanticVisitor < Crystal::Visitor | |
end | ||
|
||
def lookup_annotation(ann) | ||
# For `@[Foo]` we actually search an annotation named `FooAnnotation` | ||
path = ann.path.clone | ||
path.names[-1] = "#{path.names.last}Annotation" | ||
|
||
type = lookup_type(path) | ||
# Since there's `Int::Primitive`, and now we'll have | ||
# `::Primitive`, but there's no way to specify ::Primitive | ||
# just yet in annotations, we temporarily hardcode | ||
# that `Primitive` inside annotations means the top | ||
# level primitive. | ||
# We also have the same problem with File::Flags, which | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you put a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
# is an enum marked with Flags annotation. | ||
if ann.path.single?("Primitive") | ||
type = @program.primitive | ||
elsif ann.path.single?("Flags") | ||
type = @program.flags_annotation | ||
else | ||
type = lookup_type(ann.path) | ||
end | ||
|
||
unless type | ||
ann.raise "undefined annotation #{path}" | ||
ann.raise "undefined annotation #{ann.path}" | ||
end | ||
|
||
unless type.is_a?(AnnotationType) | ||
ann.raise "#{path} is not an annotation, it's a #{type.type_desc}" | ||
ann.raise "#{ann.path} is not an annotation, it's a #{type.type_desc}" | ||
end | ||
|
||
type | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So annotations conflicts with top level types? I would have thought they are in a separate category instead. Is it temporary?