Skip to content
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

Upgrade/deprecate remote nil calls #9769

Merged
merged 7 commits into from
Feb 1, 2020
Merged

Upgrade/deprecate remote nil calls #9769

merged 7 commits into from
Feb 1, 2020

Conversation

esse
Copy link
Contributor

@esse esse commented Jan 31, 2020

In relation to the #9510 and since we're on Elixir 1.11-dev, I've done here two points from this issue:

Deprecate Foo.bar in favor of Foo.bar()
Deprecate &Foo.bar()/0 in favor of &Foo.bar/0

Since it's my first PR touching erlang code, I would be awesome if someone could tell if this is the right approach.

@josevalim let me know if that approach is correct, and if so - I will tomorrow write tests for that :)

@@ -365,6 +365,12 @@ check_deprecated(Meta, 'Elixir.System', stacktrace, 0, #{contextual_vars := Vars
"move System.stacktrace/0 inside a rescue/catch",
elixir_errors:erl_warn(?line(Meta), ?key(E, file), Message)
end;

check_deprecated([{no_parens,true}, _] = Meta, _, _, 0, E) ->
Copy link
Member

@ericmj ericmj Jan 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -713,6 +713,16 @@ build_op({_Kind, Location, 'not in'}, Left, Right) ->
build_op({_Kind, Location, Op}, Left, Right) ->
{Op, newlines_op(Location) ++ meta_from_location(Location), [Left, Right]}.

build_unary_op({capture_op, Location, Op}, {_,_,[{_,[{no_parens,true} | _],_}, 0]} = Expr) ->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot rely on {no_parens, true} being the first element in the metadata. Instead you should use lists:keyfind/3 to look through all elements.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the capture can be built with macros and not only a literal I think we should check for parenthesis in the expansion pass like you do for the Foo.bar syntax.


check_deprecated([{no_parens,true}, _] = Meta, _, _, 0, E) ->
Message =
"Calling remote function with no arguments without parentheses is deprecated",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error messages start in lowercase. :)

@esse
Copy link
Contributor Author

esse commented Jan 31, 2020

@josevalim @ericmj thank you for you comments! I've changed stuff according to your suggestions and added tests.

@esse esse closed this Feb 1, 2020
@esse esse reopened this Feb 1, 2020
Code.eval_string("""
defmodule TestMod do
def foo(), do: nil
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no need to define a new module. Instead, let's use a zero arity function in Elixir's codebase, such as System.pid.

purge(TestMod)
end

test "deprecate remote nullary zero-arity calls without parens in a macro" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this test. :) It is not actually exercising a different branch in the codebase.

Code.eval_string("""
defmodule TestMod do
def foo(), do: nil
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, no need to define a new module. :)

purge(TestMod)
end

test "deprecate nullary remote zero-arity capture with parens in a macro" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, we can remove this test. :)

@josevalim
Copy link
Member

Thanks @esse ! I have dropped some comments to improve error messages and tests!

esse and others added 2 commits February 1, 2020 16:40
@esse
Copy link
Contributor Author

esse commented Feb 1, 2020

Thanks @josevalim - I applied all of your suggestions :)

@josevalim josevalim merged commit 66f13b7 into elixir-lang:master Feb 1, 2020
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@esse esse deleted the upgrade/deprecate-remote-nil-calls branch February 2, 2020 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants