Skip to content

Commit 65f8d0b

Browse files
VLanvinfacebook-github-bot
authored andcommitted
Error tolerance for functional args -- patching funs
Summary: Ill-typed functional arguments are sometimes never patched, making error tolerance loop indefinitely. This is because the reported erroneous expr can be a variable introduced by eta-expansion, thus it will never match a patchable expression. This diff introduces a heuristic to detect such cases and then patches the functional argument. Reviewed By: ilya-klyuchnikov Differential Revision: D43187017 fbshipit-source-id: 3741eaf59f0770922652a769d776eb7736ab00cb
1 parent 5cd3edf commit 65f8d0b

File tree

4 files changed

+6
-65
lines changed

4 files changed

+6
-65
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class Patch(erroneousExpr: Expr) {
8484
ReqMapUpdate(patchExpr(map), kvs.map(patchAtomicKV))(e.pos)
8585
case u @ GenMapUpdate(map, kvs) =>
8686
GenMapUpdate(patchExpr(map), kvs.map(patchKV))(e.pos, u.approximated)
87+
// The erroneous expr may be a variable introduced by eta-expansion of a functional argument,
88+
// in which case e == erroneousExpr will never match and the expr will not be patched.
89+
// The case below is a good enough heuristic to detect such cases.
90+
case _: LocalFun | _: RemoteFun if erroneousExpr.pos == e.pos && erroneousExpr.isInstanceOf[Var] =>
91+
dynamicCast(e)
8792
case _: Var | _: AtomLit | _: IntLit | FloatLit() | StringLit(_) | NilLit() | _: LocalFun | _: RemoteFun |
8893
_: DynRemoteFun | _: DynRemoteFunArity | _: RecordIndex =>
8994
e

eqwalizer/test_projects/_cli/stats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"fixme_count": 7,
2828
"is_generated": false,
2929
"eqwalizer_enabled": true,
30-
"error_count": 101,
30+
"error_count": 97,
3131
"is_test": false,
3232
"type_dependencies": [
3333
"misc"

eqwalizer/test_projects/fault_tolerance/src/fault_tolerance.erl.check

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -577,19 +577,3 @@ apply_map(L) -> | ERROR |
577577
map_pair(L, fun make_pair/2). | | Arg 2 of 'make_pair/2'.
578578
| | Expected: number()
579579
| | Got : term()
580-
| | ---
581-
| | Arg 2 of 'make_pair/2'.
582-
| | Expected: number()
583-
| | Got : term()
584-
| | ---
585-
| | Arg 2 of 'make_pair/2'.
586-
| | Expected: number()
587-
| | Got : term()
588-
| | ---
589-
| | Arg 2 of 'make_pair/2'.
590-
| | Expected: number()
591-
| | Got : term()
592-
| | ---
593-
| | Arg 2 of 'make_pair/2'.
594-
| | Expected: number()
595-
| | Got : term()

eqwalizer/test_projects/fault_tolerance/src/fault_tolerance.erl.json

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,54 +1152,6 @@
11521152
"expressionOrNull": null,
11531153
"explanationOrNull": null
11541154
},
1155-
{
1156-
"range": {
1157-
"start": 5291,
1158-
"end": 5306
1159-
},
1160-
"lineAndCol": null,
1161-
"message": "Expected: number()\nGot : term()",
1162-
"uri": "https://fb.me/eqwalizer_errors#expected_subtype",
1163-
"code": "expected_subtype",
1164-
"expressionOrNull": "Arg 2 of 'make_pair/2'",
1165-
"explanationOrNull": null
1166-
},
1167-
{
1168-
"range": {
1169-
"start": 5291,
1170-
"end": 5306
1171-
},
1172-
"lineAndCol": null,
1173-
"message": "Expected: number()\nGot : term()",
1174-
"uri": "https://fb.me/eqwalizer_errors#expected_subtype",
1175-
"code": "expected_subtype",
1176-
"expressionOrNull": "Arg 2 of 'make_pair/2'",
1177-
"explanationOrNull": null
1178-
},
1179-
{
1180-
"range": {
1181-
"start": 5291,
1182-
"end": 5306
1183-
},
1184-
"lineAndCol": null,
1185-
"message": "Expected: number()\nGot : term()",
1186-
"uri": "https://fb.me/eqwalizer_errors#expected_subtype",
1187-
"code": "expected_subtype",
1188-
"expressionOrNull": "Arg 2 of 'make_pair/2'",
1189-
"explanationOrNull": null
1190-
},
1191-
{
1192-
"range": {
1193-
"start": 5291,
1194-
"end": 5306
1195-
},
1196-
"lineAndCol": null,
1197-
"message": "Expected: number()\nGot : term()",
1198-
"uri": "https://fb.me/eqwalizer_errors#expected_subtype",
1199-
"code": "expected_subtype",
1200-
"expressionOrNull": "Arg 2 of 'make_pair/2'",
1201-
"explanationOrNull": null
1202-
},
12031155
{
12041156
"range": {
12051157
"start": 5291,

0 commit comments

Comments
 (0)