Skip to content

Commit d8a070d

Browse files
committed
Fix typespec to AST conversion for functions with variable arity (...)
1 parent 8a6fddd commit d8a070d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

lib/elixir/lib/kernel/typespec.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,12 @@ defmodule Kernel.Typespec do
449449
{ :"->", line, [{args, typespec_to_ast(result)}] }
450450
end
451451

452+
defp typespec_to_ast({ :type, line, :fun, [args, result] }) do
453+
{ :"->", line, [{[typespec_to_ast(args)], typespec_to_ast(result)}] }
454+
end
455+
452456
defp typespec_to_ast({ :type, line, :fun, [] }) do
453-
typespec_to_ast({ :type, line, :fun, [{:type, line, :product, [:'...']}, :any] })
457+
typespec_to_ast({ :type, line, :fun, [{:type, line, :any}, {:type,line,:any, []} ] })
454458
end
455459

456460
defp typespec_to_ast({ :type, line, name, args }) do
@@ -483,6 +487,10 @@ defmodule Kernel.Typespec do
483487
typespec_to_ast({ :ann_type, line, [{ :var, line1, name }, type] })
484488
end
485489

490+
defp typespec_to_ast({:type, _, :any}) do
491+
quote do: ...
492+
end
493+
486494
defp typespec_to_ast({ t, _line, atom }) when is_atom(t) do
487495
atom
488496
end

lib/elixir/test/elixir/typespec_test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ defmodule Typespec.Test.Type do
297297
(quote do: @type tuple_type() :: {integer()}),
298298
(quote do: @type ftype() :: (() -> any()) | (() -> integer()) | ((integer() -> integer()))),
299299
(quote do: @type cl() :: char_list()),
300+
(quote do: @type vaf() :: (... -> any())),
300301
]
301302

302303
types = test_module do

0 commit comments

Comments
 (0)