diff --git a/lib/elixir/src/elixir_def.erl b/lib/elixir/src/elixir_def.erl index f498b21176..9c14e2f2d6 100644 --- a/lib/elixir/src/elixir_def.erl +++ b/lib/elixir/src/elixir_def.erl @@ -52,16 +52,11 @@ store_definition(Line, Kind, CheckClauses, Call, Body, Pos) -> %% Check if there is a file information in the definition. %% If so, we assume this come from another source and %% we need to linify taking into account keep line numbers. - {Location, Key} = case lists:keyfind(file, 1, Meta) of - {file, KeepFile} when is_binary(KeepFile) -> - case lists:keyfind(keep, 1, Meta) of - {keep, KeepLine} when is_integer(KeepLine) -> KeepLine; - _ -> KeepLine = 0 - end, - {{KeepFile, KeepLine}, keep}; - _ -> - {nil, line} - end, + {Location, Key} = + case elixir_utils:meta_location(Meta) of + {_, _} = KeepLocation -> {KeepLocation, keep}; + nil -> {nil, line} + end, LinifyArgs = elixir_quote:linify(Line, Key, Args), LinifyGuards = elixir_quote:linify(Line, Key, Guards), diff --git a/lib/elixir/src/elixir_errors.erl b/lib/elixir/src/elixir_errors.erl index f4a3010a01..0a39b8da1f 100644 --- a/lib/elixir/src/elixir_errors.erl +++ b/lib/elixir/src/elixir_errors.erl @@ -26,7 +26,7 @@ form_error(Meta, File, Module, Desc) -> -spec form_warn(list(), binary(), module(), any()) -> ok. form_warn(Meta, File, Module, Desc) when is_list(Meta) -> - {MetaLine, MetaFile} = meta_location(Meta, File), + {MetaFile, MetaLine} = meta_location(Meta, File), warn(MetaLine, MetaFile, format_error(Module, Desc)). %% Compilation error. @@ -200,7 +200,7 @@ handle_file_error(File, {Line, Module, Desc}) -> %% Helpers raise(Meta, File, Kind, Message) when is_list(Meta) -> - {MetaLine, MetaFile} = meta_location(Meta, File), + {MetaFile, MetaLine} = meta_location(Meta, File), do_raise(MetaLine, MetaFile, Kind, Message). file_format(0, File) -> @@ -240,15 +240,9 @@ translate_comp_op('=/=') -> '!=='; translate_comp_op(Other) -> Other. meta_location(Meta, File) -> - case lists:keyfind(file, 1, Meta) of - {file, MetaFile} when is_binary(MetaFile) -> - case lists:keyfind(keep, 1, Meta) of - {keep, MetaLine} when is_integer(MetaLine) -> ok; - _ -> MetaLine = 0 - end, - {MetaLine, MetaFile}; - _ -> - {?line(Meta), File} + case elixir_utils:meta_location(Meta) of + {F, L} -> {F, L}; + nil -> {File, ?line(Meta)} end. do_warn(Warning) -> diff --git a/lib/elixir/src/elixir_utils.erl b/lib/elixir/src/elixir_utils.erl index 4ad71d2e66..18b11556af 100644 --- a/lib/elixir/src/elixir_utils.erl +++ b/lib/elixir/src/elixir_utils.erl @@ -1,7 +1,7 @@ %% Convenience functions used throughout elixir source code %% for ast manipulation and querying. -module(elixir_utils). --export([elixir_to_erl/1, get_line/1, split_last/1, +-export([elixir_to_erl/1, get_line/1, split_last/1, meta_location/1, characters_to_list/1, characters_to_binary/1, macro_name/1, convert_to_boolean/4, returns_boolean/1, atom_concat/1, read_file_type/1, read_link_type/1, relative_to_cwd/1, erl_call/4]). @@ -65,6 +65,27 @@ characters_to_binary(Data) -> false -> 'Elixir.List':to_string(Data) end. +%% Meta location. +%% +%% Macros add a file+keep pair on location keep +%% which we should take into account for report +%% reporting. +%% +%% Returns {binary, integer} on location keep or +%% nil. + +meta_location(Meta) -> + case lists:keyfind(file, 1, Meta) of + {file, MetaFile} when is_binary(MetaFile) -> + case lists:keyfind(keep, 1, Meta) of + {keep, MetaLine} when is_integer(MetaLine) -> ok; + _ -> MetaLine = 0 + end, + {MetaFile, MetaLine}; + _ -> + nil + end. + %% elixir to erl. Handles only valid quoted expressions, %% that's why things like maps and references are not in the list.