Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support catch expr #250

Merged
merged 4 commits into from
Jun 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/derivation-rules.saty
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,17 @@ but extended by remote call, local call, list, etc.
}
);
>
+small-block<
+math(
${
\derive?:{\paren{\mathsc{CATCH}}}{
| \judgement{A}{e}{\tau}{C} |
}{
\judgement{A}{\mathtt!{catch}\ e}{\mathtt!{any\(\)}}{C}
}
}
);
>
+section{Differences from the original paper}<
+p{
The differences from the derivation rules on the original paper are as follows.
Expand Down
2 changes: 2 additions & 0 deletions lib/ast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type t =
| ListNil of line
| MapCreation of (t * t) list (* #{k1 => v1, ...} *)
| MapUpdate of {map: t; assocs: (t * t) list; exact_assocs: (t * t) list} (* M#{k1 => v1, ..., ke1 := ve1, ...} *)
| Catch of line * t
and fun_abst = {args: string list; body: t}
and pattern = pattern' * t
and pattern' =
Expand Down Expand Up @@ -52,6 +53,7 @@ let line_number_of_t = function
| ListNil line -> line
| MapCreation _ -> -1
| MapUpdate _ -> -1
| Catch (line, _) -> line

let string_of_t t =
[%sexp_of: t] t |> Sexplib.Sexp.to_string_hum ~indent:2
Expand Down
3 changes: 3 additions & 0 deletions lib/derivation.ml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ let rec derive context = function
(* TODO: fully support map update. see: https://github.com/dwango/fialyzer/issues/102#issuecomment-461787511 *)
derive context map >>= fun (ty_map, c_map) ->
Ok (Type.of_elem TyAnyMap, C.Conj [c_map; C.Subtype {lhs=ty_map; rhs=Type.of_elem TyAnyMap; link=map}])
| Catch (line, body) ->
derive context body >>= fun (_, c) ->
Ok (Type.TyAny, c)
and derive_pattern context pattern =
begin match pattern with
| PatVar _ | PatTuple _ | PatConstant _ | PatCons (_, _) | PatNil ->
Expand Down
6 changes: 3 additions & 3 deletions lib/from_erlang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,9 @@ and expr_of_erlang_expr' = function
failwith "cannot reach here"
) in
Case (line, expr_of_erlang_expr' expr, cs)
| ExprCatch _ ->
raise Known_error.(FialyzerError (NotImplemented {issue_links=["https://github.com/dwango/fialyzer/issues/223"];
message="support catch expr"}))
| ExprCatch {line; expr} ->
let e = expr_of_erlang_expr' expr in
Catch (line, e)
| ExprLocalFunRef {line; function_name; arity} ->
Ref(line, LocalFun {function_name; arity})
| ExprRemoteFunRef {line; module_name; function_name; arity} ->
Expand Down
8 changes: 8 additions & 0 deletions test/blackbox-test/test-cases/try_catch_expr.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
-module(try_catch_expr).

-export([main/0]).

-spec main() -> any().
main() ->
catch 1 + 2.

1 change: 1 addition & 0 deletions test/blackbox-test/test-cases/try_catch_expr.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done (passed successfully)