Skip to content

Commit

Permalink
erl_syntax_lib annotate correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkoMin committed Sep 13, 2024
1 parent 3ff36ef commit 898343c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/syntax_tools/src/erl_syntax_lib.erl
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ vann(Tree, Env) ->
{ann_bindings(Tree, Env, Bound, Free), Bound, Free};
match_expr ->
vann_match_expr(Tree, Env);
maybe_match_expr ->
vann_maybe_match_expr(Tree, Env);
case_expr ->
vann_case_expr(Tree, Env);
if_expr ->
Expand Down Expand Up @@ -554,6 +556,17 @@ vann_match_expr(Tree, Env) ->
Tree1 = rewrite(Tree, erl_syntax:match_expr(P1, E1)),
{ann_bindings(Tree1, Env, Bound, Free), Bound, Free}.

vann_maybe_match_expr(Tree, Env) ->
E = erl_syntax:maybe_match_expr_body(Tree),
{E1, Bound1, Free1} = vann(E, Env),
Env1 = ordsets:union(Env, Bound1),
P = erl_syntax:maybe_match_expr_pattern(Tree),
{P1, Bound2, Free2} = vann_pattern(P, Env1),
Bound = ordsets:union(Bound1, Bound2),
Free = ordsets:union(Free1, Free2),
Tree1 = rewrite(Tree, erl_syntax:maybe_match_expr(P1, E1)),
{ann_bindings(Tree1, Env, Bound, Free), Bound, Free}.

vann_case_expr(Tree, Env) ->
E = erl_syntax:case_expr_argument(Tree),
{E1, Bound1, Free1} = vann(E, Env),
Expand Down Expand Up @@ -765,6 +778,16 @@ vann_pattern(Tree, Env) ->
Free = ordsets:union(Free1, Free2),
Tree1 = rewrite(Tree, erl_syntax:match_expr(P1, E1)),
{ann_bindings(Tree1, Env, Bound, Free), Bound, Free};
maybe_match_expr ->
%% Alias pattern
P = erl_syntax:maybe_match_expr_pattern(Tree),
{P1, Bound1, Free1} = vann_pattern(P, Env),
E = erl_syntax:maybe_match_expr_body(Tree),
{E1, Bound2, Free2} = vann_pattern(E, Env),
Bound = ordsets:union(Bound1, Bound2),
Free = ordsets:union(Free1, Free2),
Tree1 = rewrite(Tree, erl_syntax:maybe_match_expr(P1, E1)),
{ann_bindings(Tree1, Env, Bound, Free), Bound, Free};
macro ->
%% The macro name must be ignored. The arguments are treated
%% as patterns.
Expand Down

0 comments on commit 898343c

Please sign in to comment.