-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Deprecate complex module expressions in &mod.fun/arity captures #14095
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
Conversation
lib/elixir/src/elixir_fn.erl
Outdated
| ok; | ||
| {Var, _, Ctx} when is_atom(Var), is_atom(Ctx) -> | ||
| ok; | ||
| _ -> |
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.
Add a TODO to convert to error on v2.0 :)
|
For the warning, i would say:
However, I know realize that this is only ambiguous for zero arity functions, there is no ambiguity here: Should we abandon this? Perhaps only keep the first commit as a refactoring? |
@josevalim I'm not sure I follow, what is the difference with arity 0? fn x -> expr().flatten(x) end
# or
mod = expr()
fn x -> mod.flatten(x) endSo I think we could deprecate it in both cases? |
|
You are right, it applies to all equally. And if we deprecate, we should definitely deprecate all arities. The biggest question then is: do we expect |
For me the biggest argument is that whatever is the current behavior, we have to maintain it for backward compatibility or might break user code accidentally. Whereas if we officially warn/raise, we tell users not to rely on this and keep the surface of the valid syntax we support smaller. Regarding |
|
But I don't feel strongly about it, given it has been emitting warnings since 1.17 I don't expect the syntax to be widespread anyway. We can probably close? |
|
To expand a bit why we should close:
Arguments for deprecating:
|
It's not only you, I read it exactly the same. |
|
So let’s deprecate it. The error message should say something like:
The fn/end syntax bit only applies to zero arity. For multiple arities, it should say to use the capture operator with &1, &2, … WDYT? |
|
@josevalim I applied your previous suggestion 8617fe6, I think it looked good. Are you worried "a regular anonymous function" would be unclear? Also, are you suggesting we should spell out the actual proposed syntax, or just a hard-coded explanation? |
|
I think using fn -> is better than saying. I also didn’t consider non-zero arities :) |
Close #14091
Separated the first commit for easier review: 5f5ef9c
We needed to make the decision after expansion, so we need to distinguish if we come from the arity notation and propagate this info.
Using the example from #14089:
Feedback welcome on the wording, this isn't my strong suit :)