From 95ad8eb58dd4c64367d36cec26e21bf16319c19f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Thu, 21 Jan 2016 13:22:06 +0100 Subject: [PATCH] Include where the module being redefined is currently loaded from --- lib/elixir/src/elixir_module.erl | 13 +++++++++++-- lib/iex/test/iex/helpers_test.exs | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/elixir/src/elixir_module.erl b/lib/elixir/src/elixir_module.erl index 49cce7d763..147505db78 100644 --- a/lib/elixir/src/elixir_module.erl +++ b/lib/elixir/src/elixir_module.erl @@ -544,9 +544,18 @@ format_error({internal_function_overridden, {Name, Arity}}) -> format_error({invalid_module, Module}) -> io_lib:format("invalid module name: ~ts", ['Elixir.Kernel':inspect(Module)]); format_error({module_defined, Module}) -> - io_lib:format("redefining module ~ts", [elixir_aliases:inspect(Module)]); + Extra = + case code:which(Module) of + Path when is_list(Path) -> + io_lib:format(" (current version loaded from ~ts)", [elixir_utils:relative_to_cwd(Path)]); + in_memory -> + " (current version defined in memory)"; + _ -> + "" + end, + io_lib:format("redefining module ~ts~ts", [elixir_aliases:inspect(Module), Extra]); format_error({module_reserved, Module}) -> io_lib:format("module ~ts is reserved and cannot be defined", [elixir_aliases:inspect(Module)]); format_error({module_in_definition, Module, File, Line}) -> io_lib:format("cannot define module ~ts because it is currently being defined in ~ts:~B", - [elixir_aliases:inspect(Module), 'Elixir.Path':relative_to_cwd(File), Line]). + [elixir_aliases:inspect(Module), elixir_utils:relative_to_cwd(File), Line]). diff --git a/lib/iex/test/iex/helpers_test.exs b/lib/iex/test/iex/helpers_test.exs index f6c3a0b893..8d0b7296f4 100644 --- a/lib/iex/test/iex/helpers_test.exs +++ b/lib/iex/test/iex/helpers_test.exs @@ -341,7 +341,7 @@ defmodule IEx.HelpersTest do assert_raise UndefinedFunctionError, "undefined function Sample.run/0", fn -> Sample.run end - end) =~ ~r"^.*?sample\.ex:1: warning: redefining module Sample\n$" + end) =~ ~r"^.*?sample\.ex:1: warning: redefining module Sample \(current version loaded from Elixir.Sample.beam\)\n$" end after # Clean up old version produced by the r helper