Skip to content

Commit

Permalink
Ensure parser always returns erl_anno:location() in errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gomoripeti committed Nov 26, 2021
1 parent ae1c256 commit 73e7cea
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/erlfmt_parse.yrl
Original file line number Diff line number Diff line change
Expand Up @@ -1049,13 +1049,19 @@ parse_node(Tokens) ->
case parse(Tokens) of
{ok, _} = Res ->
Res;
Error ->
{error, {AnnoOrLoc, Mod, Description}} ->
case parse([{standalone_exprs, element(2, hd(Tokens))} | Tokens]) of
{ok, _} = Res -> Res;
_ -> Error
_ -> {error, {error_location(AnnoOrLoc), Mod, Description}}
end
end.

-spec error_location(erlfmt_scan:anno() | erl_anno:location()) -> erl_anno:location().
error_location(#{location := Loc}) ->
Loc;
error_location(Loc) ->
Loc.

%% unwrap single-expr definitions, wrapped in guards by the parser
build_macro_def(
{'-', Anno},
Expand Down

0 comments on commit 73e7cea

Please sign in to comment.