-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Emit warning when variable is being expanded to function call #3517
Conversation
I think the goal is to warn only if inside a function, i.e. |
@@ -313,6 +313,8 @@ expand({Name, Meta, Kind} = Var, #{vars := Vars} = E) when is_atom(Name), is_ato | |||
compile_error(Meta, ?m(E, file), "expected var \"~ts\"~ts to expand to an existing variable " | |||
"or be part of a match", [Name, elixir_scope:context_info(Kind)]); | |||
true -> | |||
Message = io_lib:format("variable ~ts is used as function call", [Name]), |
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.
We need to add to the error message: ", please use parentheses to remove the ambiguity and solve this warning"
52697ad
to
1ef9c99
Compare
@lexmag just a heads up: let's move this to 1.3. There are already quite some changes in 1.1 and 1.2 is meant to be completely compatible. So 1.3 is when we can start pushing this. |
5b2317f
to
f201ee8
Compare
I'm still wondering if it'll be considered inconsistent if we emit this warning only inside functions. |
What do you mean by only inside functions? We should always emit it, |
Yes, but previously (Jul 21, 2015) we thought "to warn only if inside a function". The only downside of not checking if "function isn't nil" is the following: |
|
When compiling a project using the schema "my_schema" do
field :my_field, :string
timestamps()
end which I think does not look very DSL like. I did not look at the implementation details yet, but do you think it would be possible and worth to handle such a case? |
@tuvistavie |
I understand you point, and the point of this warning, html do
body do
h1 "foobar"
br()
end
end Having to make an explicit function call here kind of looses the beauty of the DSL in my opinion. |
@tuvistavie it depends on the DSL. Some DSLs will bypass this warning by simply annotating those variables as generated or by translating the AST. For example, |
@josevalim Thank you for the explanation. |
Yes, that's a possibility, definitely. We will continue collecting feedback on this in any case. :) |
I use Elixir 1.3.2 and I don't see the warning when I try this code: defmodule WarningTest do
defp do_stuff, do: 'stuff'
def my_func do
do_stuff
a = do_stuff
end
end |
@ivanvotti this warning will be part of Elixir v1.4.0. |
Late to the party, but I cannot seem to find this in the v1.4.0 changelog. Is there any reason this was omitted? |
https://github.com/elixir-lang/elixir/blob/v1.4/CHANGELOG.md |
Okay, searched for bare words and arity. Sorry for the noise, then. |
No problem! |
Closes #3268.