From e2d96a871cd1117b0779051da2cb31bc28a23371 Mon Sep 17 00:00:00 2001 From: Akos Hajdu Date: Tue, 3 Sep 2024 13:07:37 -0700 Subject: [PATCH] [erlang] More tests on matching against already bound variables Summary: Add a test for simple "reassignment" and using the anonymus placeholder `_`. Reviewed By: lisztspace Differential Revision: D62126763 fbshipit-source-id: a8779efb7148a19db7e7fb1158fd68b1c9d15a70 --- .../codetoanalyze/erlang/compiler/issues.exp | 4 ++++ .../pulse/nonmatch/nonmatch_match_expr.erl | 24 ++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/infer/tests/codetoanalyze/erlang/compiler/issues.exp b/infer/tests/codetoanalyze/erlang/compiler/issues.exp index 2bbd15dcb39..c524add5022 100644 --- a/infer/tests/codetoanalyze/erlang/compiler/issues.exp +++ b/infer/tests/codetoanalyze/erlang/compiler/issues.exp @@ -661,7 +661,11 @@ 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:fn_test_not_real_anon_match1_Bad/0: badmatch +nonmatch_match_expr:fn_test_not_real_anon_match2_Bad/0: badmatch +nonmatch_match_expr:fn_test_simple_match_Bad/0: badmatch nonmatch_match_expr:test_match_a_Ok/0: ok +nonmatch_match_expr:test_match_anonymus_Ok/0: ok nonmatch_match_expr:test_match_b_Bad/0: badmatch nonmatch_match_expr:test_match_c_Ok/0: ok nonmatch_match_expr:test_match_d_Ok/0: ok diff --git a/infer/tests/codetoanalyze/erlang/pulse/nonmatch/nonmatch_match_expr.erl b/infer/tests/codetoanalyze/erlang/pulse/nonmatch/nonmatch_match_expr.erl index 64d5f328745..3d96992101b 100644 --- a/infer/tests/codetoanalyze/erlang/pulse/nonmatch/nonmatch_match_expr.erl +++ b/infer/tests/codetoanalyze/erlang/pulse/nonmatch/nonmatch_match_expr.erl @@ -31,7 +31,11 @@ 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 + fn_test_match_with_var_swapped_Bad/0, + fn_test_simple_match_Bad/0, + test_match_anonymus_Ok/0, + fn_test_not_real_anon_match1_Bad/0, + fn_test_not_real_anon_match2_Bad/0 ]). tail([_ | Xs]) -> Xs. @@ -165,3 +169,21 @@ test_match_with_var_swapped_Ok() -> fn_test_match_with_var_swapped_Bad() -> crash_if_not_one_with_var_swapped(2). + +fn_test_simple_match_Bad() -> + A = 1, + A = 2. + +test_match_anonymus_Ok() -> + _ = 1, + _ = 2. + +fn_test_not_real_anon_match1_Bad() -> + % `_` is the only truly anonymus name + _A = 1, + _A = 2. + +fn_test_not_real_anon_match2_Bad() -> + % `_` is the only truly anonymus name + __ = 1, + __ = 2.