Skip to content

Commit 2fbbdd1

Browse files
hajduakosmeta-codesync[bot]
authored andcommitted
[erl-frontend] Parse strict bitstring generators
Summary: We don't support them during translation, but at least parse them. Reviewed By: rgrig Differential Revision: D91224325 fbshipit-source-id: 6eab1e2d1b022503201b07db8edd3b42ca466152
1 parent 67d2237 commit 2fbbdd1

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

infer/src/erlang/ErlangAst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ and simple_expression =
111111
and expression = {location: location; simple_expression: simple_expression}
112112

113113
and qualifier =
114-
| BitsGenerator of {pattern: expression; expression: expression}
114+
| BitsGenerator of {pattern: expression; expression: expression; strict: bool}
115115
| Filter of expression
116116
| Generator of {pattern: expression; expression: expression; strict: bool}
117117
| MapGenerator of {pattern: association; expression: expression; strict: bool}

infer/src/erlang/ErlangJsonParser.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,11 @@ and to_qualifier gen_uniq json : Ast.qualifier option =
508508
| `List [`String "b_generate"; _anno; pattern; expression] ->
509509
let* pattern = to_expression gen_uniq pattern in
510510
let* expression = to_expression gen_uniq expression in
511-
Some (Ast.BitsGenerator {pattern; expression})
511+
Some (Ast.BitsGenerator {pattern; expression; strict= false})
512+
| `List [`String "b_generate_strict"; _anno; pattern; expression] ->
513+
let* pattern = to_expression gen_uniq pattern in
514+
let* expression = to_expression gen_uniq expression in
515+
Some (Ast.BitsGenerator {pattern; expression; strict= true})
512516
| `List [`String "generate"; _anno; pattern; expression] ->
513517
let* pattern = to_expression gen_uniq pattern in
514518
let* expression = to_expression gen_uniq expression in

infer/tests/codetoanalyze/erlang/compiler/issues.exp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ features_arithmetic:test_uminus1_Ok/0: ok
7070
features_arithmetic:test_uminus2_Bad/0: expected_crash
7171
features_arithmetic:test_uminus2_Ok/0: ok
7272

73+
----- features_bc -----
74+
features_bc:fn_test_strict_Bad/0: bad_generator
75+
features_bc:test_strict_Ok/0: ok
76+
7377
----- features_binary_attr -----
7478
features_binary_attr:test_bad_Bad/0: expected_crash
7579
features_binary_attr:test_ok_Ok/0: ok
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
% Copyright (c) Facebook, Inc. and its affiliates.
2+
%
3+
% This source code is licensed under the MIT license found in the
4+
% LICENSE file in the root directory of this source tree.
5+
6+
-module(features_bc).
7+
8+
-export([
9+
test_strict_Ok/0,
10+
fn_test_strict_Bad/0
11+
]).
12+
13+
test_strict_Ok() ->
14+
[X || <<X>> <:= <<1>>].
15+
16+
% We don't support bitstring generators
17+
fn_test_strict_Bad() ->
18+
[X || <<X>> <:= nope].

0 commit comments

Comments
 (0)