Skip to content

Commit

Permalink
Fix parser crash on 'fun F/A'
Browse files Browse the repository at this point in the history
  • Loading branch information
plux committed Sep 20, 2024
1 parent 029ebe2 commit 917d15f
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions apps/els_lsp/src/els_parser.erl
Original file line number Diff line number Diff line change
Expand Up @@ -929,32 +929,39 @@ implicit_fun(Tree) ->
| undefined.
try_analyze_implicit_fun(Tree) ->
FunName = erl_syntax:implicit_fun_name(Tree),
ModQBody = erl_syntax:module_qualifier_body(FunName),
ModQArg = erl_syntax:module_qualifier_argument(FunName),
case erl_syntax:type(ModQBody) of
arity_qualifier ->
AqBody = erl_syntax:arity_qualifier_body(ModQBody),
AqArg = erl_syntax:arity_qualifier_argument(ModQBody),
case {erl_syntax:type(ModQArg), erl_syntax:type(AqBody), erl_syntax:type(AqArg)} of
{macro, atom, integer} ->
M = erl_syntax:variable_name(erl_syntax:macro_name(ModQArg)),
F = erl_syntax:atom_value(AqBody),
A = erl_syntax:integer_value(AqArg),
case M of
'MODULE' ->
{F, A};
_ ->
case erl_syntax:type(FunName) of
module_qualifier ->
ModQBody = erl_syntax:module_qualifier_body(FunName),
ModQArg = erl_syntax:module_qualifier_argument(FunName),
case erl_syntax:type(ModQBody) of
arity_qualifier ->
AqBody = erl_syntax:arity_qualifier_body(ModQBody),
AqArg = erl_syntax:arity_qualifier_argument(ModQBody),
case
{erl_syntax:type(ModQArg), erl_syntax:type(AqBody), erl_syntax:type(AqArg)}
of
{macro, atom, integer} ->
M = erl_syntax:variable_name(erl_syntax:macro_name(ModQArg)),
F = erl_syntax:atom_value(AqBody),
A = erl_syntax:integer_value(AqArg),
case M of
'MODULE' ->
{F, A};
_ ->
undefined
end;
{ModType, FunType, integer} when
ModType =:= variable orelse ModType =:= atom,
FunType =:= variable orelse FunType =:= atom
->
M = node_name(ModQArg),
F = node_name(AqBody),
A = erl_syntax:integer_value(AqArg),
{{ModType, M}, {FunType, F}, A};
_Types ->
undefined
end;
{ModType, FunType, integer} when
ModType =:= variable orelse ModType =:= atom,
FunType =:= variable orelse FunType =:= atom
->
M = node_name(ModQArg),
F = node_name(AqBody),
A = erl_syntax:integer_value(AqArg),
{{ModType, M}, {FunType, F}, A};
_Types ->
_Type ->
undefined
end;
_Type ->
Expand Down

0 comments on commit 917d15f

Please sign in to comment.