diff --git a/infer/src/erlang/ErlangTranslator.ml b/infer/src/erlang/ErlangTranslator.ml index cbf48013f..f3822c962 100644 --- a/infer/src/erlang/ErlangTranslator.ml +++ b/infer/src/erlang/ErlangTranslator.ml @@ -461,6 +461,12 @@ and translate_expression env {Ast.line; simple_expression} = Sil.Call ((ret_var, any), fun_exp, args, env.location, CallFlags.default) in Block.all env [head_block; tail_block; Block.make_instruction env [call_instruction]] + | If clauses -> + let blocks = Block.any env (List.map ~f:(translate_case_clause env []) clauses) in + let crash_node = Node.make_pattern_fail env in + blocks.exit_failure |~~> [crash_node] ; + let blocks = {blocks with exit_failure= crash_node} in + blocks | Literal (Atom atom) -> let hash = (* With this hack, an atom may accidentaly be considered equal to an unrelated integer. diff --git a/infer/tests/codetoanalyze/erlang/nonmatch/issues.exp b/infer/tests/codetoanalyze/erlang/nonmatch/issues.exp index 81bc64d24..d9fe5e3c9 100644 --- a/infer/tests/codetoanalyze/erlang/nonmatch/issues.exp +++ b/infer/tests/codetoanalyze/erlang/nonmatch/issues.exp @@ -22,6 +22,8 @@ codetoanalyze/erlang/nonmatch/src/function_guards.erl, possible_exception/1, 0, codetoanalyze/erlang/nonmatch/src/function_guards.erl, test_accepts_positive2_Bad/0, -23, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `accepts_positive2/1`,no pattern match here] codetoanalyze/erlang/nonmatch/src/function_guards.erl, test_accepts_positive_Bad/0, -19, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `accepts_positive/1`,no pattern match here] codetoanalyze/erlang/nonmatch/src/function_guards.erl, test_possible_exception_Bad/0, -37, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `possible_exception/1`,no pattern match here] +codetoanalyze/erlang/nonmatch/src/if_expression.erl, accepts_positive/1, 1, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [*** LATENT ***,no pattern match here] +codetoanalyze/erlang/nonmatch/src/if_expression.erl, test_accepts_positive_Bad/0, -13, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `accepts_positive/1`,no pattern match here] codetoanalyze/erlang/nonmatch/src/match.erl, fp_match_test_c_Ok/0, 1, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [no pattern match here] codetoanalyze/erlang/nonmatch/src/match.erl, fp_match_test_d_Ok/0, -13, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `tail/1`,no pattern match here] codetoanalyze/erlang/nonmatch/src/match.erl, match_test_b_Bad/0, 1, CONSTANT_ADDRESS_DEREFERENCE, no_bucket, WARNING, [in call to `two/0`,is the constant 2,assigned,returned,return from call to `two/0`,invalid access occurs here] diff --git a/infer/tests/codetoanalyze/erlang/nonmatch/src/if_expression.erl b/infer/tests/codetoanalyze/erlang/nonmatch/src/if_expression.erl new file mode 100644 index 000000000..cafe1a688 --- /dev/null +++ b/infer/tests/codetoanalyze/erlang/nonmatch/src/if_expression.erl @@ -0,0 +1,33 @@ +% Copyright (c) Facebook, Inc. and its affiliates. +% +% This source code is licensed under the MIT license found in the +% LICENSE file in the root directory of this source tree. + +-module(if_expression). + +-export([ + test_accepts_positive_Ok/0, + test_accepts_positive_Bad/0, + test_accepts_all_Ok/0 +]). + +accepts_positive(X) -> + if + X > 0 -> ok + end. + +accepts_all(X) -> + if + X > 0 -> ok; + not (X > 0) -> ok + end. + +test_accepts_positive_Ok() -> + accepts_positive(1). + +test_accepts_positive_Bad() -> + accepts_positive(0). + +test_accepts_all_Ok() -> + accepts_all(0), + accepts_all(1).