Skip to content

Commit 2a50097

Browse files
hajduakosfacebook-github-bot
authored andcommitted
[erl-frontend] Add some error messages to AST validator
Summary: Improve AST validator by logging reasons of invalid AST. Reviewed By: mmarescotti Differential Revision: D42191179 fbshipit-source-id: 18fa1a6378756d9afd729d484bb6f2b505a0879b
1 parent 56b8926 commit 2a50097

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

infer/src/erlang/ErlangAstValidator.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ let rec validate_pattern env (p : Ast.expression) =
6565
| Exact ->
6666
validate_pattern env a.key && validate_pattern env a.value
6767
| _ ->
68+
L.debug Capture Verbose "Invalid map association kind (not :=) in pattern@." ;
6869
false
6970
in
7071
is_none map && List.for_all ~f:validate_assoc updates
@@ -99,11 +100,12 @@ let validate_patterns env = List.for_all ~f:(validate_pattern env)
99100

100101
(** Guards are expressions in general, but with restrictions and constraints. *)
101102

102-
let is_atom (e : Ast.expression) =
103+
let validate_guard_call_func (e : Ast.expression) =
103104
match e.simple_expression with
104105
| Literal lit -> (
105106
match lit with Atom _ -> true | _ -> false )
106107
| _ ->
108+
L.debug Capture Verbose "Function in guard is not an atom@." ;
107109
false
108110

109111

@@ -114,8 +116,14 @@ let validate_guard_call_module (eo : Ast.expression option) =
114116
| Some e -> (
115117
match e.simple_expression with
116118
| Literal lit -> (
117-
match lit with Atom "erlang" -> true | _ -> false )
119+
match lit with
120+
| Atom "erlang" ->
121+
true
122+
| _ ->
123+
L.debug Capture Verbose "Non-erlang module in call in a guard@." ;
124+
false )
118125
| _ ->
126+
L.debug Capture Verbose "Non-atom module in call in a guard@." ;
119127
false )
120128

121129

@@ -128,7 +136,7 @@ let rec validate_guard_test env (gt : Ast.expression) =
128136
List.for_all ~f:(validate_elem env) elems
129137
| Call {module_; function_; args} ->
130138
validate_guard_call_module module_
131-
&& is_atom function_
139+
&& validate_guard_call_func function_
132140
&& List.for_all ~f:(validate_guard_test env) args
133141
| Cons {head; tail} ->
134142
validate_guard_test env head && validate_guard_test env tail
@@ -141,6 +149,7 @@ let rec validate_guard_test env (gt : Ast.expression) =
141149
| Arrow ->
142150
validate_guard_test env a.key && validate_guard_test env a.value
143151
| _ ->
152+
L.debug Capture Verbose "Invalid map association kind (not =>) in map create@." ;
144153
false
145154
in
146155
(* Map update accepts '=>' and ':=' *)
@@ -220,6 +229,7 @@ let rec validate_expr env (expr : Ast.expression) =
220229
| Arrow ->
221230
validate_expr env a.key && validate_expr env a.value
222231
| _ ->
232+
L.debug Capture Verbose "Invalid map association kind (not =>) in map create@." ;
223233
false
224234
in
225235
(* Map update accepts '=>' and ':=' *)

0 commit comments

Comments
 (0)