Skip to content

Commit 051f9bb

Browse files
committed
do not emit alias_reference on alias expansion in typespec
1 parent c057721 commit 051f9bb

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

lib/elixir_sense/core/compiler/quote.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
defmodule ElixirSense.Core.Compiler.Quote do
22
alias ElixirSense.Core.Compiler.Dispatch
33
alias ElixirSense.Core.Normalized.Macro.Env, as: NormalizedMacroEnv
4-
alias ElixirSense.Core.Compiler.State
54

65
defstruct line: false,
76
file: nil,

lib/elixir_sense/core/compiler/typespec.ex

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ defmodule ElixirSense.Core.Compiler.Typespec do
22
alias ElixirSense.Core.Compiler
33
alias ElixirSense.Core.Compiler.Utils
44
alias ElixirSense.Core.Compiler.State
5+
alias ElixirSense.Core.Normalized.Macro.Env, as: NormalizedMacroEnv
6+
57
def spec_to_signature({:when, _, [spec, _]}), do: type_to_signature(spec)
68
def spec_to_signature(other), do: type_to_signature(other)
79

@@ -618,7 +620,27 @@ defmodule ElixirSense.Core.Compiler.Typespec do
618620
{nil, state}
619621
end
620622

621-
defdelegate expand_remote(other, env), to: ElixirSense.Core.Compiler.Macro, as: :expand
623+
# This is a modified backport of Macro.expand/2 because we want to expand
624+
# aliases but we don't them to become compile-time references.
625+
defp expand_remote({:__aliases__, meta, [head | tail] = list} = alias, env) do
626+
# TODO pass true to track alias_expansion?
627+
case NormalizedMacroEnv.expand_alias(env, meta, list, trace: false) do
628+
{:alias, alias} ->
629+
alias
630+
631+
:error ->
632+
head = ElixirSense.Core.Compiler.Macro.expand(head, env)
633+
634+
if is_atom(head) do
635+
Module.concat([head | tail])
636+
else
637+
# elixir raises here
638+
alias
639+
end
640+
end
641+
end
642+
643+
defp expand_remote(other, env), do: ElixirSense.Core.Compiler.Macro.expand(other, env)
622644

623645
defp remote_type({{:., dot_meta, [remote_spec, name_spec]}, meta, args}, vars, caller, state) do
624646
{args, state} = :lists.mapfoldl(&typespec(&1, vars, caller, &2), state, args)

lib/elixir_sense/core/normalized/macro/env.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ defmodule ElixirSense.Core.Normalized.Macro.Env do
2525
false ->
2626
allow_locals = Keyword.get(opts, :allow_locals, true)
2727
trace = Keyword.get(opts, :trace, true)
28-
module = env.module
28+
# module = env.module
2929

3030
# elixir version passes module.__info__(:macros) as extra, we do not need that
3131
# instead we override local_for_callback
@@ -638,7 +638,7 @@ defmodule ElixirSense.Core.Normalized.Macro.Env do
638638
fn args, caller -> expand_macro_fun(meta, fun, receiver, name, args, caller, e) end
639639
end
640640

641-
defp expand_macro_fun(_meta, fun, _receiver, name, args, caller, _e) do
641+
defp expand_macro_fun(_meta, fun, _receiver, _name, args, caller, _e) do
642642
# elixir applies local macro via apply/2
643643
# we need to check if the macro is a function as we return a fake for local macros
644644
if is_function(fun) do

test/elixir_sense/core/metadata_builder_test.exs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7578,7 +7578,6 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
75787578

75797579
assert %{
75807580
2 => [
7581-
_,
75827581
_,
75837582
%CallInfo{
75847583
arity: 0,
@@ -7604,7 +7603,6 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
76047603
assert %{
76057604
2 => [
76067605
%CallInfo{arity: 1, func: :@, position: {2, 3}, mod: Kernel},
7607-
%CallInfo{kind: :alias_reference},
76087606
%CallInfo{
76097607
arity: 0,
76107608
func: :t,
@@ -7615,7 +7613,6 @@ defmodule ElixirSense.Core.MetadataBuilderTest do
76157613
],
76167614
3 => [
76177615
%CallInfo{arity: 1, func: :@, position: {3, 3}, mod: Kernel},
7618-
%CallInfo{kind: :alias_reference},
76197616
%CallInfo{
76207617
arity: 0,
76217618
func: :t,

0 commit comments

Comments
 (0)