From c82308e5860aa635e4d7e6fce9f62b05ca60011f Mon Sep 17 00:00:00 2001 From: Akos Hajdu Date: Thu, 8 Jul 2021 08:50:44 -0700 Subject: [PATCH] [erl-frontend] Support block expressions Summary: Add support for block expressions in the translation. Reviewed By: rgrig Differential Revision: D29584072 fbshipit-source-id: 2a1a1eeda --- infer/src/erlang/ErlangTranslator.ml | 2 + .../codetoanalyze/erlang/features/issues.exp | 2 + .../erlang/features/src/block.erl | 37 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 infer/tests/codetoanalyze/erlang/features/src/block.erl diff --git a/infer/src/erlang/ErlangTranslator.ml b/infer/src/erlang/ErlangTranslator.ml index 5d19b1c05..5261cdb85 100644 --- a/infer/src/erlang/ErlangTranslator.ml +++ b/infer/src/erlang/ErlangTranslator.ml @@ -367,6 +367,8 @@ and translate_expression env {Ast.line; simple_expression} = Block.make_success env in Block.all env [block1; block2; op_block] + | Block body -> + translate_body env body | Call { module_= None ; function_= {Ast.line= _; simple_expression= Literal (Atom function_name)} diff --git a/infer/tests/codetoanalyze/erlang/features/issues.exp b/infer/tests/codetoanalyze/erlang/features/issues.exp index 4a7bb55ec..fad3f86c9 100644 --- a/infer/tests/codetoanalyze/erlang/features/issues.exp +++ b/infer/tests/codetoanalyze/erlang/features/issues.exp @@ -11,3 +11,5 @@ codetoanalyze/erlang/features/src/arithmetic.erl, test_sub2_Bad/0, -54, NONEXHAU codetoanalyze/erlang/features/src/arithmetic.erl, test_uminus1_Bad/0, -170, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here] codetoanalyze/erlang/features/src/arithmetic.erl, test_uminus2_Bad/0, -183, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here] codetoanalyze/erlang/features/src/arithmetic.erl, warn/1, 0, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [*** LATENT ***,no pattern match here] +codetoanalyze/erlang/features/src/block.erl, test_block_Bad/0, -15, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [calling context starts here,in call to `warn/1`,no pattern match here] +codetoanalyze/erlang/features/src/block.erl, warn/1, 0, NONEXHAUSTIVE_PATTERN_MATCH, no_bucket, ERROR, [*** LATENT ***,no pattern match here] diff --git a/infer/tests/codetoanalyze/erlang/features/src/block.erl b/infer/tests/codetoanalyze/erlang/features/src/block.erl new file mode 100644 index 000000000..3db3b9e48 --- /dev/null +++ b/infer/tests/codetoanalyze/erlang/features/src/block.erl @@ -0,0 +1,37 @@ +% 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(block). + +-export([test_block_Ok/0, test_block_Bad/0]). + +% Call this method with warn(1) to trigger a warning to expect +warn(0) -> ok. + +test_block_Ok() -> + case + begin + X = 3, + Y = X, + Z = Y, + Z + end + of + 3 -> ok; + _ -> warn(1) + end. + +test_block_Bad() -> + case + begin + X = 3, + Y = X, + Z = Y, + Z + end + of + 3 -> warn(1); + _ -> ok + end.