Skip to content

Commit

Permalink
Merge pull request #250 from dwango/feature/catch_expr
Browse files Browse the repository at this point in the history
Support catch expr
  • Loading branch information
yoshihiro503 authored Jun 3, 2019
2 parents 8aac92e + ee5eeef commit 5a8dd17
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 3 deletions.
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)

0 comments on commit 5a8dd17

Please sign in to comment.