Skip to content

Commit

Permalink
[erlang] Add more tests on pattern matching with case
Browse files Browse the repository at this point in the history
Summary: Add more tests with pattern matching using a local variable in a case expression. Also, moved tests into the other tests with case expressions as both files are quite small, I think it makes more sense to have them in one place.

Reviewed By: mmarescotti

Differential Revision: D62123479

fbshipit-source-id: 02ad894be32b087aa59c486c7c716c6eeacebf07
  • Loading branch information
hajduakos authored and facebook-github-bot committed Sep 3, 2024
1 parent 17520f2 commit 0accd99
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 27 deletions.
8 changes: 4 additions & 4 deletions infer/tests/codetoanalyze/erlang/compiler/issues.exp
Original file line number Diff line number Diff line change
Expand Up @@ -561,16 +561,16 @@ nonmatch_atoms:test_match6_Bad/0: function_clause
nonmatch_atoms:test_match7_Bad/0: function_clause

----- nonmatch_case_expr -----
nonmatch_case_expr:fn_test_arg_Bad/0: case_clause
nonmatch_case_expr:fn_test_local_var_Bad/0: case_clause
nonmatch_case_expr:test_arg_Ok/0: ok
nonmatch_case_expr:test_case_simple1_Ok/0: ok
nonmatch_case_expr:test_case_simple2_Ok/0: ok
nonmatch_case_expr:test_case_simple3_Bad/0: case_clause
nonmatch_case_expr:test_case_tail1_Ok/0: ok
nonmatch_case_expr:test_case_tail2_Ok/0: ok
nonmatch_case_expr:test_case_tail3_Bad/0: case_clause

----- nonmatch_case_expr_arg -----
nonmatch_case_expr_arg:fn_test_Bad/0: case_clause
nonmatch_case_expr_arg:test_Ok/0: ok
nonmatch_case_expr:test_local_var_Ok/0: ok

----- nonmatch_case_guards -----
nonmatch_case_guards:test_accepts_all_Ok/0: ok
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
test_case_simple3_Bad/0,
test_case_tail1_Ok/0,
test_case_tail2_Ok/0,
test_case_tail3_Bad/0
test_case_tail3_Bad/0,
test_arg_Ok/0,
fn_test_arg_Bad/0,
test_local_var_Ok/0,
fn_test_local_var_Bad/0
]).

case_simple(X) ->
Expand All @@ -38,3 +42,27 @@ test_case_tail2_Ok() ->
tail_with_case([1]).
test_case_tail3_Bad() ->
tail_with_case([]).

crash_if_different(A, B) ->
% The matching of A against the bound B should be compiled to an equality check.
case A of
B -> ok
end.

test_arg_Ok() ->
crash_if_different(0, 0).
fn_test_arg_Bad() ->
crash_if_different(0, 1).

crash_if_not_one(A) ->
B = 1,
% The matching of A against the bound B should be compiled to an equality check.
case A of
B -> ok
end.

test_local_var_Ok() ->
crash_if_not_one(1).

fn_test_local_var_Bad() ->
crash_if_not_one(2).

This file was deleted.

0 comments on commit 0accd99

Please sign in to comment.