Skip to content

Commit 75de28b

Browse files
VLanvinfacebook-github-bot
authored andcommitted
Restrict allowed operators when converting exprs to guards
Summary: Conversion of expressions to guards is only possible for certain allowed operators (for example, `++` is not accepted in a guard expression). Reviewed By: RobinMorisset Differential Revision: D41377868 fbshipit-source-id: 02efee2e02a23fe68c546786716ffe85eaede2b0
1 parent d8afa8e commit 75de28b

File tree

7 files changed

+57
-15
lines changed

7 files changed

+57
-15
lines changed

eqwalizer/src/main/scala/com/whatsapp/eqwalizer/ast/Filters.scala

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,37 @@ object Filters {
2828
"is_tuple",
2929
)
3030

31+
val guards_binop: Set[String] =
32+
Set(
33+
"/",
34+
"*",
35+
"-",
36+
"+",
37+
"div",
38+
"rem",
39+
"band",
40+
"bor",
41+
"bxor",
42+
"bsl",
43+
"bsr",
44+
"or",
45+
"xor",
46+
"and",
47+
">=",
48+
">",
49+
"=<",
50+
"<",
51+
"/=",
52+
"=/=",
53+
"==",
54+
"=:=",
55+
"andalso",
56+
"orelse",
57+
)
58+
59+
val guards_unop: Set[String] =
60+
Set("bnot", "+", "-", "not")
61+
3162
private def isPredicateFun(name: String, arity: Int): Boolean =
3263
(name, arity) match {
3364
case (_, 1) =>
@@ -54,11 +85,11 @@ object Filters {
5485
for {
5586
argsT <- asTests(args)
5687
} yield TestCall(Id(f, arity), argsT)(expr.pos)
57-
case UnOp(op, arg) =>
88+
case UnOp(op, arg) if guards_unop(op) =>
5889
for {
5990
argT <- asTest(arg)
6091
} yield TestUnOp(op, argT)(expr.pos)
61-
case BinOp(op, arg1, arg2) =>
92+
case BinOp(op, arg1, arg2) if guards_binop(op) =>
6293
for {
6394
arg1T <- asTest(arg1)
6495
arg2T <- asTest(arg2)

eqwalizer/test_projects/_cli/checkable_funs.cli

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
all funs:
2-
All : 2773
3-
Checkable : 2512
2+
All : 2774
3+
Checkable : 2513
44
Well-typed checkable : 1615
55
Checkable ratio : 91%
66
Health ratio of checkable : 64%
7-
error count : 896
7+
error count : 897
88

99
--------------------------------------------
1010
generated funs:
@@ -26,19 +26,19 @@ generated non-test funs:
2626

2727
--------------------------------------------
2828
non-generated funs:
29-
All : 2773
30-
Checkable : 2512
29+
All : 2774
30+
Checkable : 2513
3131
Well-typed checkable : 1615
3232
Checkable ratio : 91%
3333
Health ratio of checkable : 64%
34-
error count : 896
34+
error count : 897
3535

3636
--------------------------------------------
3737
non-generated non-test funs (most important):
38-
All : 2771
39-
Checkable : 2510
38+
All : 2772
39+
Checkable : 2511
4040
Well-typed checkable : 1614
4141
Checkable ratio : 91%
4242
Health ratio of checkable : 64%
43-
error count : 895
43+
error count : 896
4444

eqwalizer/test_projects/_cli/discarded_specs.cli

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@ type_aliases:uses_trans_unbound_var/2
4949
type_aliases:uses_ty_w_unbound_var/2
5050
type_aliases:uses_ty_w_unbound_var2/0
5151
Discarded specs: 49
52-
Total specs: 2650
53-
Discarded ratio: 1.8491 %
52+
Total specs: 2651
53+
Discarded ratio: 1.8484 %
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
Average error message length: 22.09649 characters
1+
Average error message length: 22.086357 characters
22
Longest error message: 122 characters
33
Average error message length for the longest 10% of error msgs: 46.886074 characters

eqwalizer/test_projects/_cli/misc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2562,7 +2562,8 @@
25622562
"use_invalid_opaque_2/1",
25632563
"f/1",
25642564
"g/1",
2565-
"fuzz01/0"
2565+
"fuzz01/0",
2566+
"fuzz02/0"
25662567
]
25672568
},
25682569
{

eqwalizer/test_projects/check_gradual/src/gradual_misc.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@ g(#{(a #{ b => c }) := _}) ->
3232
-spec fuzz01() -> ok.
3333
fuzz01() when #{(true andalso false) => {}} ->
3434
ok.
35+
36+
-spec fuzz02() -> ok.
37+
fuzz02() ->
38+
<<X || X <- [], (X ++ X) >>.

eqwalizer/test_projects/check_gradual/src/gradual_misc.erl.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,9 @@ g(#{(a #{ b => c }) := _}) -> | OK |
3434
-spec fuzz01() -> ok. | |
3535
fuzz01() when #{(true andalso false) => {}…… OK |
3636
ok. | |
37+
| |
38+
-spec fuzz02() -> ok. | |
39+
fuzz02() -> | ERROR |
40+
<<X || X <- [], (X ++ X) >>. | | << || >>.
41+
| | Expected: 'ok'
42+
| | Got : binary()

0 commit comments

Comments
 (0)