Skip to content

Commit 114df0e

Browse files
committed
error instead of raise
1 parent 39828b0 commit 114df0e

File tree

5 files changed

+25
-12
lines changed

5 files changed

+25
-12
lines changed

ocaml/testsuite/tests/typing-modes/modes.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,18 @@ Error: Optional parameters cannot be polymorphic
291291
another PR. Here, we test that they at least parse. *)
292292
let foo ((x @ unique once), (y@local unique)) = x + y
293293
[%%expect{|
294-
>> Fatal error: Mode expressions on patterns are not supported yet
295-
Uncaught exception: Misc.Fatal_error
296-
294+
Line 1, characters 14-25:
295+
1 | let foo ((x @ unique once), (y@local unique)) = x + y
296+
^^^^^^^^^^^
297+
Error: Mode annotations on patterns are not supported yet.
297298
|}]
298299

299300
let foo ((x : _ @@ unique once), (y : _ @@ local unique)) = x + y
300301
[%%expect{|
301-
>> Fatal error: Mode expressions on patterns are not supported yet
302-
Uncaught exception: Misc.Fatal_error
303-
302+
Line 1, characters 19-30:
303+
1 | let foo ((x : _ @@ unique once), (y : _ @@ local unique)) = x + y
304+
^^^^^^^^^^^
305+
Error: Mode annotations on patterns are not supported yet.
304306
|}]
305307

306308
(* let-bound function *)
@@ -335,7 +337,8 @@ module type S = sig
335337
val x : string -> string @ local @@ foo bar
336338
end
337339
[%%expect{|
338-
>> Fatal error: Modalities not supported in value declarations
339-
Uncaught exception: Misc.Fatal_error
340-
340+
Line 337, characters 38-45:
341+
337 | val x : string -> string @ local @@ foo bar
342+
^^^^^^^
343+
Error: Modalities on value descriptions are not supported yet.
341344
|}]

ocaml/typing/typecore.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ type error =
228228
| Exclave_returns_not_local
229229
| Unboxed_int_literals_not_supported
230230
| Function_type_not_rep of type_expr * Jkind.Violation.t
231+
| Modes_on_pattern
231232

232233
exception Error of Location.t * Env.t * error
233234
exception Error_forward of Location.error
@@ -2463,7 +2464,7 @@ and type_pat_aux
24632464
pat_env = !env }
24642465
in
24652466
match Jane_syntax.Mode_expr.maybe_of_attrs sp.ppat_attributes with
2466-
| Some _, _ -> Misc.fatal_error "Mode expressions on patterns are not supported yet"
2467+
| Some modes, _ -> raise (Error (modes.loc, !env, Modes_on_pattern))
24672468
| None, _ ->
24682469
match Jane_syntax.Pattern.of_ast sp with
24692470
| Some (jpat, attrs) -> begin
@@ -4962,7 +4963,7 @@ let may_lower_contravariant_then_generalize env exp =
49624963

49634964
(* This added mode attribute is read and removed by
49644965
[alloc_mode_from_pexp_constraint_typ_attrs] or
4965-
[alloc_mode_from_pexp_constraint_typ_attrs]. *)
4966+
[alloc_mode_from_ppat_constraint_typ_attrs]. *)
49664967
let add_mode_annot_attrs mode_annot_attr typ =
49674968
match mode_annot_attr with
49684969
| None -> typ
@@ -10121,6 +10122,9 @@ let report_error ~loc env = function
1012110122
"@[Function arguments and returns must be representable.@]@ %a"
1012210123
(Jkind.Violation.report_with_offender
1012310124
~offender:(fun ppf -> Printtyp.type_expr ppf ty)) violation
10125+
| Modes_on_pattern ->
10126+
Location.errorf ~loc
10127+
"@[Mode annotations on patterns are not supported yet.@]"
1012410128
1012510129
let report_error ~loc env err =
1012610130
Printtyp.wrap_printing_env ~error:true env

ocaml/typing/typecore.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ type error =
293293
| Exclave_returns_not_local
294294
| Unboxed_int_literals_not_supported
295295
| Function_type_not_rep of type_expr * Jkind.Violation.t
296+
| Modes_on_pattern
296297

297298
exception Error of Location.t * Env.t * error
298299
exception Error_forward of Location.error

ocaml/typing/typedecl.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type error =
101101
| Local_not_enabled
102102
| Unexpected_jkind_any_in_primitive of string
103103
| Useless_layout_poly
104+
| Modalities_on_value_description
104105

105106
open Typedtree
106107

@@ -2388,7 +2389,7 @@ let error_if_containing_unexpected_jkind prim env cty ty =
23882389
(* Translate a value declaration *)
23892390
let transl_value_decl env loc valdecl =
23902391
match Jane_syntax.Mode_expr.maybe_of_attrs valdecl.pval_type.ptyp_attributes with
2391-
| Some _, _ -> Misc.fatal_error "Modalities not supported in value declarations"
2392+
| Some modes, _ -> raise (Error(modes.loc, Modalities_on_value_description))
23922393
| None, _ ->
23932394
let cty = Typetexp.transl_type_scheme env valdecl.pval_type in
23942395
(* CR layouts v5: relax this to check for representability. *)
@@ -3146,6 +3147,9 @@ let report_error ppf = function
31463147
"@[[@@layout_poly] on this external declaration has no@ \
31473148
effect. Consider removing it or adding a type@ \
31483149
variable for it to operate on.@]"
3150+
| Modalities_on_value_description ->
3151+
fprintf ppf
3152+
"@[Modalities on value descriptions are not supported yet.@]"
31493153

31503154
let () =
31513155
Location.register_error_of_exn

ocaml/typing/typedecl.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ type error =
145145
| Local_not_enabled
146146
| Unexpected_jkind_any_in_primitive of string
147147
| Useless_layout_poly
148+
| Modalities_on_value_description
148149

149150
exception Error of Location.t * error
150151

0 commit comments

Comments
 (0)