Skip to content

Commit de9feb2

Browse files
author
José Valim
committed
Deprecate x.Alias syntax
1 parent b8528f6 commit de9feb2

File tree

4 files changed

+5
-39
lines changed

4 files changed

+5
-39
lines changed

lib/elixir/lib/kernel/special_forms.ex

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -343,28 +343,9 @@ defmodule Kernel.SpecialForms do
343343
344344
Note that `Kernel."HELLO"` will be treated as a remote call and not an alias.
345345
This choice was done so every time single- or double-quotes are used, we have
346-
a remote call irregardless of the quote contents. This decision is also reflected
346+
a remote call regardless of the quote contents. This decision is also reflected
347347
in the quoted expressions discussed below.
348348
349-
## Runtime (dynamic) behaviour
350-
351-
The result returned by `.` is always specified by the right-side:
352-
353-
iex> x = String
354-
iex> x.downcase("FOO")
355-
"foo"
356-
iex> x.Sample
357-
String.Sample
358-
359-
In case the right-side is also dynamic, `.`'s behaviour can be reproduced
360-
at runtime via `apply/3` and `Module.concat/2`:
361-
362-
iex> apply(:erlang, :+, [1,2])
363-
3
364-
365-
iex> Module.concat(Kernel, Sample)
366-
Kernel.Sample
367-
368349
## Quoted expression
369350
370351
When `.` is used, the quoted expression may take two distinct
@@ -1327,22 +1308,13 @@ defmodule Kernel.SpecialForms do
13271308
13281309
On the other hand, aliases holds some properties:
13291310
1330-
1. The head element of aliases can be any term.
1311+
1. The head element of aliases can be any term that must expand to
1312+
an atom at compilation time.
13311313
13321314
2. The tail elements of aliases are guaranteed to always be atoms.
13331315
13341316
3. When the head element of aliases is the atom `:Elixir`, no expansion happen.
13351317
1336-
4. When the head element of aliases is not an atom, it is expanded at runtime:
1337-
1338-
quote do: some_var.Foo
1339-
{:__aliases__, [], [{:some_var, [], Elixir}, :Foo]}
1340-
1341-
Since `some_var` is not available at compilation time, the compiler
1342-
expands such expression to:
1343-
1344-
Module.concat [some_var, Foo]
1345-
13461318
"""
13471319
defmacro __aliases__(args)
13481320

lib/elixir/src/elixir_exp.erl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ expand({'__aliases__', _, _} = Alias, E) ->
6666
elixir_lexical:record_remote(Receiver, ?m(E, lexical_tracker)),
6767
{Receiver, EA};
6868
false ->
69+
elixir_errors:warn(?m(E, line), ?m(E, file), io_lib:format("an alias must expand to an atom "
70+
"at compilation time but got ~ts", ['Elixir.Macro':to_string(hd(EAliases))])),
6971
{{{'.', [], [elixir_aliases, concat]}, [], [EAliases]}, EA}
7072
end
7173
end;

lib/elixir/test/elixir/kernel/expansion_test.exs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ defmodule Kernel.ExpansionTest do
5555
assert expand_env(quote(do: World), __ENV__) |> elem(0) == :"Elixir.Source"
5656
end
5757

58-
test "__aliases__: expands to elixir_aliases on runtime" do
59-
assert expand(quote do: hello.World) ==
60-
quote do: :elixir_aliases.concat([hello(), :World])
61-
end
62-
6358
## =
6459

6560
test "=: sets context to match" do

lib/elixir/test/erlang/module_test.erl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ nesting_test() ->
9090
dot_alias_test() ->
9191
{'Elixir.Foo.Bar.Baz', _} = eval("Foo.Bar.Baz").
9292

93-
dot_dyn_alias_test() ->
94-
{'Elixir.Foo.Bar.Baz', _} = eval("a = Foo.Bar; a.Baz").
95-
9693
single_ref_test() ->
9794
{'Elixir.Foo', _} = eval("Foo"),
9895
{'Elixir.Foo', _} = eval("Elixir.Foo").

0 commit comments

Comments
 (0)