Skip to content

Commit

Permalink
[erlang] Add more tests for matching against bound variables
Browse files Browse the repository at this point in the history
Summary: Add more tests for matching against already bound variables, this time using `match` expressions of different forms.

Reviewed By: mmarescotti

Differential Revision: D62123911

fbshipit-source-id: 822a1db67846864591682ed741b1301a9727a63f
  • Loading branch information
hajduakos authored and facebook-github-bot committed Sep 3, 2024
1 parent 4cb46f3 commit 323916a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
8 changes: 8 additions & 0 deletions infer/tests/codetoanalyze/erlang/compiler/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,10 @@ nonmatch_maps:test_update_match_in_function_Ok/0: ok
nonmatch_maps:test_update_old_value_Ok/0: ok

----- nonmatch_match_expr -----
nonmatch_match_expr:fn_test_match_func_arg_Bad/0: badmatch
nonmatch_match_expr:fn_test_match_func_args_Bad/0: badmatch
nonmatch_match_expr:fn_test_match_with_var_Bad/0: badmatch
nonmatch_match_expr:fn_test_match_with_var_swapped_Bad/0: badmatch
nonmatch_match_expr:test_match_a_Ok/0: ok
nonmatch_match_expr:test_match_b_Bad/0: badmatch
nonmatch_match_expr:test_match_c_Ok/0: ok
Expand All @@ -665,6 +669,8 @@ nonmatch_match_expr:test_match_e_Bad/0: function_clause
nonmatch_match_expr:test_match_eager_Bad/0: badmatch
nonmatch_match_expr:test_match_eager_Ok/0: ok
nonmatch_match_expr:test_match_f_Ok/0: ok
nonmatch_match_expr:test_match_func_arg_Ok/0: ok
nonmatch_match_expr:test_match_func_args_Ok/0: ok
nonmatch_match_expr:test_match_g_Bad/0: function_clause
nonmatch_match_expr:test_match_in_pattern_a_Ok/0: ok
nonmatch_match_expr:test_match_in_pattern_b_Bad/0: case_clause
Expand All @@ -675,6 +681,8 @@ nonmatch_match_expr:test_match_in_pattern_f_Bad/0: case_clause
nonmatch_match_expr:test_match_nested1_Ok/0: ok
nonmatch_match_expr:test_match_nested2_Bad/0: badmatch
nonmatch_match_expr:test_match_nested3_Bad/0: badmatch
nonmatch_match_expr:test_match_with_var_Ok/0: ok
nonmatch_match_expr:test_match_with_var_swapped_Ok/0: ok

----- nonmatch_maybe -----
nonmatch_maybe:test_maybe1_Ok/0: ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,15 @@
test_match_nested2_Bad/0,
test_match_nested3_Bad/0,
test_match_eager_Ok/0,
test_match_eager_Bad/0
test_match_eager_Bad/0,
test_match_func_args_Ok/0,
fn_test_match_func_args_Bad/0,
test_match_func_arg_Ok/0,
fn_test_match_func_arg_Bad/0,
test_match_with_var_Ok/0,
fn_test_match_with_var_Bad/0,
test_match_with_var_swapped_Ok/0,
fn_test_match_with_var_swapped_Bad/0
]).

tail([_ | Xs]) -> Xs.
Expand Down Expand Up @@ -117,3 +125,43 @@ test_match_eager_Bad() ->

only_accepts_one(1) -> ok.
two() -> 2.

%% Tests for matching against already bound variables

crash_if_different(A, B) ->
A = B.

test_match_func_args_Ok() ->
crash_if_different(1, 1).

fn_test_match_func_args_Bad() ->
crash_if_different(1, 2).

crash_if_not_one(A) ->
A = 1.

test_match_func_arg_Ok() ->
crash_if_not_one(1).

fn_test_match_func_arg_Bad() ->
crash_if_not_one(2).

crash_if_not_one_with_var(A) ->
B = 1,
A = B.

test_match_with_var_Ok() ->
crash_if_not_one_with_var(1).

fn_test_match_with_var_Bad() ->
crash_if_not_one_with_var(2).

crash_if_not_one_with_var_swapped(A) ->
B = 1,
B = A.

test_match_with_var_swapped_Ok() ->
crash_if_not_one_with_var_swapped(1).

fn_test_match_with_var_swapped_Bad() ->
crash_if_not_one_with_var_swapped(2).

0 comments on commit 323916a

Please sign in to comment.