elixir-lang / ex_doc

ExDoc produces HTML and EPUB documentation for Elixir projects
http://elixir-lang.org
Other
1.44k stars 325 forks source link

ArgumentError when using integer() in @spec #886

Closed janpieper closed 6 years ago

janpieper commented 6 years ago

When I try to run ex_doc for my library, I am getting an ArgumentError in ExDoc.Formatter.HTML.Autolink.format_and_extract_typespec_placeholders/4. I was able to reproduce it with a simple mix new example project.

When I have the following module, everything is fine:

defmodule Example do
  @spec hello(String.t()) :: String.t()
  def hello(name), do: "Hello #{name}"
end

But, when I change the @spec to use integer() instead of String.t():

defmodule Example do
  @spec hello(integer()) :: String.t()
  def hello(people), do: "Hello, we are #{people} people!"
end

I get the following error:

$ ex_doc "Example" "v0.1.0" _build/dev/lib/example/ebin
=ERROR REPORT==== 21-Aug-2018::19:55:05.793109 ===
** Task <0.83.0> terminating
** Started from <0.82.0>
** When function  == #Fun<Elixir.ExDoc.Formatter.HTML.Autolink.30.36958183>
**      arguments == []
** Reason for termination == 
** {badarg,
       [{'Elixir.ExDoc.Formatter.HTML.Autolink',
            '-format_and_extract_typespec_placeholders/4-fun-0-',7,
            [{file,"lib/ex_doc/formatter/html/autolink.ex"},{line,240}]},
        {'Elixir.Macro','-do_traverse_args/4-fun-0-',4,
            [{file,"lib/macro.ex"},{line,277}]},
        {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',3,
            [{file,"lib/enum.ex"},{line,1397}]},
        {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',3,
            [{file,"lib/enum.ex"},{line,1397}]},
        {'Elixir.Macro',do_traverse,4,[{file,"lib/macro.ex"},{line,243}]},
        {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',3,
            [{file,"lib/enum.ex"},{line,1397}]},
        {'Elixir.Macro',do_traverse,4,[{file,"lib/macro.ex"},{line,243}]},
        {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',3,
            [{file,"lib/enum.ex"},{line,1397}]}]}

=CRASH REPORT==== 21-Aug-2018::19:55:05.796421 ===
  crasher:
    initial call: Elixir.ExDoc.Formatter.HTML.Autolink:'-all/3-fun-2-'/0
    pid: <0.83.0>
    registered_name: []
    exception exit: {badarg,
                        [{'Elixir.ExDoc.Formatter.HTML.Autolink',
                             '-format_and_extract_typespec_placeholders/4-fun-0-',
                             7,
                             [{file,"lib/ex_doc/formatter/html/autolink.ex"},
                              {line,240}]},
                         {'Elixir.Macro','-do_traverse_args/4-fun-0-',4,
                             [{file,"lib/macro.ex"},{line,277}]},
                         {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',
                             3,
                             [{file,"lib/enum.ex"},{line,1397}]},
                         {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',
                             3,
                             [{file,"lib/enum.ex"},{line,1397}]},
                         {'Elixir.Macro',do_traverse,4,
                             [{file,"lib/macro.ex"},{line,243}]},
                         {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',
                             3,
                             [{file,"lib/enum.ex"},{line,1397}]},
                         {'Elixir.Macro',do_traverse,4,
                             [{file,"lib/macro.ex"},{line,243}]},
                         {'Elixir.Enum','-map_reduce/3-lists^mapfoldl/2-0-',
                             3,
                             [{file,"lib/enum.ex"},{line,1397}]}]}
      in function  'Elixir.Task.Supervised':exit/4 (lib/task/supervised.ex, line 121)
      in call from 'Elixir.Task.Supervised':reply/5 (lib/task/supervised.ex, line 38)
    ancestors: [<0.82.0>]
    message_queue_len: 0
    messages: []
    links: [<0.82.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 6772
    stack_size: 27
    reductions: 41541
  neighbours:
    neighbour:
      pid: <0.82.0>
      registered_name: []
      initial_call: {erlang,apply,2}
      current_function: {'Elixir.Task',await,2}
      ancestors: []
      message_queue_len: 0
      links: [<0.83.0>]
      trap_exit: false
      status: waiting
      heap_size: 28690
      stack_size: 25
      reductions: 9876
      current_stacktrace: [{'Elixir.Task',await,2,[{file,"lib/task.ex"},{line,491}]},
                  {'Elixir.Enum','-map/2-lists^map/1-0-',2,
                      [{file,"lib/enum.ex"},{line,1294}]},
                  {'Elixir.ExDoc.Formatter.HTML',run,2,
                      [{file,"lib/ex_doc/formatter/html.ex"},{line,21}]},
                  {'Elixir.Kernel.CLI','-exec_fun/2-fun-0-',3,
                      [{file,"lib/kernel/cli.ex"},{line,105}]}]

** (EXIT from #PID<0.82.0>) an exception was raised:
    ** (ArgumentError) argument error
        (ex_doc) lib/ex_doc/formatter/html/autolink.ex:240: anonymous fn/7 in ExDoc.Formatter.HTML.Autolink.format_and_extract_typespec_placeholders/4
        (elixir) lib/macro.ex:277: anonymous fn/4 in Macro.do_traverse_args/4
        (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir) lib/macro.ex:243: Macro.do_traverse/4
        (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
        (elixir) lib/macro.ex:243: Macro.do_traverse/4
        (elixir) lib/enum.ex:1397: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3

I am using the following versions:

$ mix --version
Erlang/OTP 21 [erts-10.0] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Mix 1.6.6 (compiled with OTP 19)

$ ex_doc -v
ExDoc v0.18.4
josevalim commented 6 years ago

Thanks @janpieper! This seems to be fixed on the v0.19.1, although that requires Elixir v1.7:

image

janpieper commented 6 years ago

Hmmm... 0.18.4 has a bug which is fixed in 0.19, but this requires Elixir 1.7?

Do you know if I can use any earlier version than 0.18.4 that does not have this bug? Will try this tomorrow.

janpieper commented 6 years ago
janpieper commented 6 years ago

Btw.: When doing mix docs, it also works with 0.18.4 :astonished:

milmazz commented 6 years ago

@janpieper So, should we close this issue then? I could not reproduce your scenario with the latest release from ExDoc.

josevalim commented 6 years ago

when using an escript, the elixir source is bundled inside the escript, which causes the errors. But since both cases have been fixed in 0.19, we are good to go. :)