Skip to content

Commit 73e7cea

Browse files
committed
Ensure parser always returns erl_anno:location() in errors
1 parent ae1c256 commit 73e7cea

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/erlfmt_parse.yrl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,13 +1049,19 @@ parse_node(Tokens) ->
10491049
case parse(Tokens) of
10501050
{ok, _} = Res ->
10511051
Res;
1052-
Error ->
1052+
{error, {AnnoOrLoc, Mod, Description}} ->
10531053
case parse([{standalone_exprs, element(2, hd(Tokens))} | Tokens]) of
10541054
{ok, _} = Res -> Res;
1055-
_ -> Error
1055+
_ -> {error, {error_location(AnnoOrLoc), Mod, Description}}
10561056
end
10571057
end.
10581058

1059+
-spec error_location(erlfmt_scan:anno() | erl_anno:location()) -> erl_anno:location().
1060+
error_location(#{location := Loc}) ->
1061+
Loc;
1062+
error_location(Loc) ->
1063+
Loc.
1064+
10591065
%% unwrap single-expr definitions, wrapped in guards by the parser
10601066
build_macro_def(
10611067
{'-', Anno},

0 commit comments

Comments
 (0)