Closed fenollp closed 5 years ago
The error is happening in the parser, which means we don't even have a notion of module attributes yet. The issue is that you are trying to write this: @Bar 2
, which is the same as +Bar 2
, which we can reduce to Bar 2
, and it shows that you can't pass arguments to aliases because you can't "call" them.
I understand the error message is quite bad but all error messages coming from the parser are going to be this bad, unfortunately, and generally speaking there isn't much we can do unless we rewrite the whole parser in a tool with better error messages that I am not sure exists at the moment . Sorry. :(
Wait. How is @Bar 2
the same as +Bar 2
?
@ in Elixir is a unary operator, like +.
Alright but what makes @
====== +
? As I understand it the reason @
disappears is because it gets turned into a plus sign?
The error is happening in the parser, which means we don't even have a notion of module attributes yet. The issue is that you are trying to write this: @Bar 2, which is the same as +Bar 2, which we can reduce to Bar 2, and it shows that you can't pass arguments to aliases because you can't "call" them.
@fenollp I have no idea what you are talking about :)
Sorry, I didn’t mean to say that @ is literally equal to @, but just that it is also an operator. For example, if the error also manifests for +Bar 2, then it shows it is not a module attribute issue, but a more general one. --
José Valimwww.plataformatec.com.br http://www.plataformatec.com.br/Founder and Director of R&D
So? Accept atoms around @
/ write a special case to your parser? I don't care how it's done, lots of newcomers get bitten by this and it appears terribly unfortunate that the compiler doesn't even catch this.
This cannot be a wontfix.
@fenollp if you believe the change is straight-forward, then a pull request is absolutely welcome. I personally can't see how to address this and it isn't the first time I try but I may as well be missing something obvious.
Also, as my previous comments tried to explain, this is not related to @
at all. quote do: @Bar
is actually valid AST and it must remain so. But again, I may be missing something obvious.
@fenollp the documentation for custom module attributes has been clarified a bit https://github.com/elixir-lang/elixir/pull/9109. Hope it helps! 🙂
Environment
Elixir 1.8.2 (compiled with Erlang/OTP 21)
Darwin baobao 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64 i386 MacBookPro14,1 Darwin
Expected behaviour
Either
Module attributes cannot be capitalized. See @Bla in lib/m.ex:2