-
-
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
Fix Reference#dup of file private class #3858
Fix Reference#dup of file private class #3858
Conversation
For instance: private class Foo end Foo.new.dup this code causes an error: Error in foo.cr:4: instantiating 'Foo#dup()' Foo.new.dup ^~~ in /.../src/reference.cr:40: expanding macro {% if @type.abstract? %} ^ in macro 'macro_XXX' /.../src/reference.cr:40, line 2: 1. > 2. dup = Foo.allocate 3. dup.as(Void*).copy_from(self.as(Void*), instance_sizeof(Foo)) 4. dup 5. This commit fixes it by wrapping {{@type}} expansion with #<loc:> pragma of class defined location.
@@ -140,7 +140,7 @@ struct Int | |||
|
|||
{% begin %} | |||
if self < 0 && self == {{@type}}::MIN && other == -1 | |||
raise ArgumentError.new "overflow: {{@type}}::MIN / -1" | |||
raise ArgumentError.new "overflow: {{@type.id}}::MIN / -1" |
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.
This is a breaking change
I closed this because this introduces breaking changes. I believe a better solution is to improve macros. Maybe macro interpolation A specific solution for |
@asterite Macros in comment is disallowed, isn't it? If we can disallow macro in string literal, I think we can decide whether to output loc pragama on context, it is better. |
Macros are allowed everywhere, including within comments. |
But if loc pragma is emitted always, your comment will be so dirty. |
Well, it renders properly in Crystal docs. |
That's why I think the macros system should be improved, because when you pass nodes to them there's no easy way to preserve their location. And blindly outputting loc pragmas isn't the correct solution (for the |
For instance:
this code causes an error:
This commit fixes it by wrapping
{{@type}}
expansion with#<loc:>
pragmaof class defined location.