Skip to content

Commit dbdcf48

Browse files
hajduakosfacebook-github-bot
authored andcommitted
[erl-frontend] Be less restrictive on map pattern keys
Summary: [This document](https://www.erlang.org/doc/apps/erts/absform.html#patterns) says > If P is a map pattern #{A_1, ..., A_k}, where each A_i is an association P_i_1 := P_i_2, which implied to us that both keys and values have to be patterns themselves. But [this other document](https://www.erlang.org/doc/reference_manual/expressions.html#maps-in-patterns) says > The key K must be a guard expression, with all variables already bound. V can be any pattern with either bound or unbound variables. and seems like the compiler also implements the latter. So adjusting our validation. Reviewed By: mmarescotti Differential Revision: D42191306 fbshipit-source-id: 6d5d96c51380719916a10f11c2a511b176afa2a4
1 parent 2a50097 commit dbdcf48

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

infer/src/erlang/ErlangAstValidator.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let rec validate_pattern env (p : Ast.expression) =
6363
let validate_assoc (a : Ast.association) =
6464
match a.kind with
6565
| Exact ->
66-
validate_pattern env a.key && validate_pattern env a.value
66+
validate_guard_test env a.key && validate_pattern env a.value
6767
| _ ->
6868
L.debug Capture Verbose "Invalid map association kind (not :=) in pattern@." ;
6969
false
@@ -94,13 +94,12 @@ let rec validate_pattern env (p : Ast.expression) =
9494
false
9595

9696

97-
let validate_patterns env = List.for_all ~f:(validate_pattern env)
97+
and validate_patterns env = List.for_all ~f:(validate_pattern env)
9898

9999
(** {2 Guards} *)
100-
101100
(** Guards are expressions in general, but with restrictions and constraints. *)
102101

103-
let validate_guard_call_func (e : Ast.expression) =
102+
and validate_guard_call_func (e : Ast.expression) =
104103
match e.simple_expression with
105104
| Literal lit -> (
106105
match lit with Atom _ -> true | _ -> false )
@@ -109,7 +108,7 @@ let validate_guard_call_func (e : Ast.expression) =
109108
false
110109

111110

112-
let validate_guard_call_module (eo : Ast.expression option) =
111+
and validate_guard_call_module (eo : Ast.expression option) =
113112
match eo with
114113
| None ->
115114
true
@@ -127,7 +126,7 @@ let validate_guard_call_module (eo : Ast.expression option) =
127126
false )
128127

129128

130-
let rec validate_guard_test env (gt : Ast.expression) =
129+
and validate_guard_test env (gt : Ast.expression) =
131130
match gt.simple_expression with
132131
| BinaryOperator (e1, _, e2) ->
133132
validate_guard_test env e1 && validate_guard_test env e2

0 commit comments

Comments
 (0)