Permalink
Browse files

Add support for access macro in typespecs

  • Loading branch information...
1 parent edf34ed commit 856cd70d86f26157a07ed512ad5db5c8d2245f2f @yrashk committed Oct 30, 2012
Showing with 14 additions and 0 deletions.
  1. +6 −0 lib/elixir/lib/kernel/typespec.ex
  2. +8 −0 lib/elixir/test/elixir/typespec_test.exs
@@ -106,6 +106,12 @@ defmodule Kernel.Typespec do
{ :op, line, op, {:integer, line, integer} }
end
+ # Handle access macro
+ defp typespec({{:., line, [Kernel, :access]}, line1, [target, args]}, vars, caller) do
+ access = {{:., line, [Kernel, :access]}, line1,
+ [target, args ++ [_: (quote hygiene: false, do: any)]]}
+ typespec(Macro.expand(access, caller), vars, caller)
+ end
# Handle remote calls
defp typespec({{:., line, [remote, name]}, _, args}, vars, caller) do
remote = Macro.expand remote, caller
@@ -163,6 +163,14 @@ defmodule Typespec.Test.Type do
{:type, _, :atom, []}]}, []}} = spec
end
+ test "@type with an access macro" do
+ spec = test_module do
+ @type mytype :: Range[first: integer]
+ end
+ assert {:type,{:mytype,{:type, _, :tuple,
+ [{:atom, _, Range}, {:type, _, :integer, []}, {:type, _, :any, []}]}, []}} = spec
+ end
+
test "@type with parameters" do
{spec1, spec2, spec3} = test_module do
t1 = @type mytype(x) :: x

1 comment on commit 856cd70

@devinus

Beautiful.

Please sign in to comment.