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
Can't use property name :: Type
when name is a keyword
#284
Comments
That's a terrible word :). Can.t you |
I just ran into this issue here. |
It's actually in the first post, "happened to someone else" :) |
I was thinking that the type of input arguments to methods are specified via single colons, so this tempts me to think that using double colons to specify the type of properties is not so desired due to lack of unification. One option would be to use |
I'll close this. In the case of JSON mapping we do it another way. For other macros that would't like to delegate to this property syntax, the solution is to use write the setters/getters manually (it's just a few lines). |
Right now we support this:
This makes use of the
name :: String
syntax, which is used to declare a variable with a type. The AST node representing this expression is what get passed to theproperty
macro.Buf this doesn't work:
The problem is that
end :: Time
is not a valid expression, becauseend
is a keyword and you can't have a variable namedend
.This innocent limitation becomes harder to detect when a macro in turn uses this macro. For example until this commit you couldn't declare a json mapping with keywords as names. That commit's "solution" was to write the contents of the
property
macro with a bit more thought. But it's (just a bit) annoying and make code reusability less effective.This happened to me once, and now it happened to someone else. That means we have to do something about it.
Possible solutions:
typed_property
, that would accept two AST nodes:typed_property end, Time
. With this option we could remove theproperty foo :: Bar
syntax to avoid these mistakes, or just leave both options so you can choose the one that's more readable to you.property
(and similar macros) not accept a list of nodes. So doingproperty foo, bar, baz
would be impossible. But add an overload toproperty
that accepts two arguments:property foo, Int32
.end :: Time
to be a valid expression. The "problem" is that this doesn't make sense in real code as you can't later refer to theend
variable, so would be a hack in my opinion (but a pragmatic hack :-P).property
with a type restriction in other macros.The text was updated successfully, but these errors were encountered: