diff --git a/lib/elixir/lib/behaviour.ex b/lib/elixir/lib/behaviour.ex index bdde6b594e5..c58cd2574e3 100644 --- a/lib/elixir/lib/behaviour.ex +++ b/lib/elixir/lib/behaviour.ex @@ -109,7 +109,7 @@ defmodule Behaviour do end def __behaviour__(:docs) do - @__behaviour_docs__ + Enum.reverse(@__behaviour_docs__) end end end diff --git a/lib/elixir/test/elixir/behaviour_test.exs b/lib/elixir/test/elixir/behaviour_test.exs index 11a111c2383..facc54b34c9 100644 --- a/lib/elixir/test/elixir/behaviour_test.exs +++ b/lib/elixir/test/elixir/behaviour_test.exs @@ -6,27 +6,35 @@ defmodule BehaviourTest do defmodule Sample do use Behaviour + @doc "I should be first." + defcallback first(integer) :: integer + @doc "Foo" defcallback foo(atom, binary) :: binary @doc "Bar" defcallback bar(External.hello, my_var :: binary) :: binary + + @doc "I should be last." + defcallback last(integer) :: integer end test :docs do - docs = Enum.sort(Sample.__behaviour__(:docs)) + docs = Sample.__behaviour__(:docs) assert docs == [ - {{:bar, 2}, 13, "Bar"}, - {{:foo, 2}, 10, "Foo"} + {{:first, 1}, 10, "I should be first."}, + {{:foo, 2}, 13, "Foo"}, + {{:bar, 2}, 16, "Bar"}, + {{:last, 1}, 19, "I should be last."} ] end test :callbacks do - assert Sample.__behaviour__(:callbacks) == [foo: 2, bar: 2] + assert Sample.__behaviour__(:callbacks) == [first: 1, foo: 2, bar: 2, last: 1] end test :specs do - assert length(Keyword.get_values(Sample.module_info[:attributes], :callback)) == 2 + assert length(Keyword.get_values(Sample.module_info[:attributes], :callback)) == 4 end test :default_is_not_supported do