Skip to content

Commit

Permalink
add missing expand call on union
Browse files Browse the repository at this point in the history
fix crash with expand call on unexpandable vars and other
  • Loading branch information
lukaszsamson committed Nov 5, 2023
1 parent 0e1b928 commit 894d9d6
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
13 changes: 11 additions & 2 deletions lib/elixir_sense/core/binding.ex
Original file line number Diff line number Diff line change
Expand Up @@ -948,10 +948,19 @@ defmodule ElixirSense.Core.Binding do
# not a module
defp expand_call(_env, {:atom, _mod}, _fun, _arity, _include_private, _stack), do: :none

defp expand_call(_env, target, fun, arity, include_private, _stack) do
raise "No clause matched #{inspect(target)}, #{inspect(fun)}, #{inspect(arity)}, #{inspect(include_private)}"
defp expand_call(env, {:union, variants}, fun, arity, include_private, stack) do
# TODO choose variant by args?
Enum.find_value(variants, fn variant ->
res = expand_call(env, variant |> dbg, fun, arity, include_private, stack)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 25.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.12.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test (Elixir 1.13.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.12.x | Erlang/OTP 22.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.12.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.12.x | Erlang/OTP 24.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 23.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

Check failure on line 954 in lib/elixir_sense/core/binding.ex

View workflow job for this annotation

GitHub Actions / mix test windows (Elixir 1.13.x | Erlang/OTP 25.x)

** (CompileError) lib/elixir_sense/core/binding.ex:954: undefined function dbg/1 (expected ElixirSense.Core.Binding to define such a function or for it to be imported, but none are available)

if res != :none do
res
end
end)
end

defp expand_call(_env, _target, _fun, _arity, _include_private, _stack), do: nil

defp call_arity_match?(fun_arity, fun_defaults, call_arity) do
fun_arity - fun_defaults <= call_arity and call_arity <= fun_arity
end
Expand Down
19 changes: 18 additions & 1 deletion test/elixir_sense/core/binding_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ defmodule ElixirSense.Core.BindingTest do
end

test "remote call fun with spec intersection different returns" do
assert {:union, [{:map, [abc: nil], nil}, {:atom, nil}]} ==
assert {:union, [{:map, [abc: {:atom, String}], nil}, {:atom, nil}]} ==
Binding.expand(
@env
|> Map.put(:variables, [
Expand All @@ -936,6 +936,23 @@ defmodule ElixirSense.Core.BindingTest do
)
end

test "remote call fun with spec intersection different returns nested" do
assert {:atom, String} ==
Binding.expand(
@env
|> Map.put(:variables, [
%VarInfo{
name: :ref,
type:
{:call,
{:call, {:atom, ElixirSenseExample.FunctionsWithReturnSpec}, :f7, []},
:abc, []}
}
]),
{:variable, :ref}
)
end

test "remote call fun with spec intersection same returns" do
assert {:map, [abc: nil], nil} ==
Binding.expand(
Expand Down
2 changes: 1 addition & 1 deletion test/support/functions_with_return_spec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ defmodule ElixirSenseExample.FunctionsWithReturnSpec do
@spec f6() :: %{abc: atom}
def f6(), do: :ok

@spec f7() :: %{abc: atom}
@spec f7() :: %{abc: String}
@spec f7() :: nil
def f7(), do: :ok

Expand Down

0 comments on commit 894d9d6

Please sign in to comment.