Skip to content

Commit 54e3fe6

Browse files
authored
flambda-backend: Tolerate global in transl_mode_annots (#2326)
* assert prints useful location * more test * make fmt * ignore global in alloc_mode
1 parent aa5fd28 commit 54e3fe6

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

testsuite/tests/typing-local/local.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,11 @@ type gfoo = GFoo of global_ string * string
25402540
type gfoo = GFoo of global_ string * string
25412541
|}]
25422542
2543+
type gfoo' = GFoo' : global_ string -> gfoo'
2544+
[%%expect{|
2545+
type gfoo' = GFoo' : global_ string -> gfoo'
2546+
|}]
2547+
25432548
(* TESTING OF GLOBAL_ *)
25442549
25452550
(* global arguments must be global when constructing

typing/typemode.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,13 @@ let transl_mode_annots modes =
2727
match acc.linearity with
2828
| None -> { acc with linearity = Some Linearity.Const.Once }
2929
| Some _ -> raise (Error (loc, Duplicated_mode `Linearity)))
30-
| s -> Misc.fatal_errorf "Unrecognized mode %s - should not parse" s
30+
| "global" ->
31+
(* CR zqian: global modality might leak to here by ppxes.
32+
This is a dirty fix that needs to be fixed ASAP. *)
33+
acc
34+
| s ->
35+
Misc.fatal_errorf "Unrecognized mode %s at %a - should not parse" s
36+
Location.print_loc loc
3137
in
3238
loop acc rest
3339
in
@@ -45,8 +51,12 @@ let transl_global_flags gfs =
4551
match acc with
4652
| Unrestricted -> Global_flag.Global
4753
| Global ->
48-
Misc.fatal_error "Duplicated global modality - should not parse")
49-
| s -> Misc.fatal_errorf "Unrecognized modality %s - should not parse" s
54+
Misc.fatal_errorf
55+
"Duplicated global modality at %a - should not parse"
56+
Location.print_loc loc)
57+
| s ->
58+
Misc.fatal_errorf "Unrecognized modality %s at %a - should not parse"
59+
s Location.print_loc loc
5060
in
5161
loop acc rest
5262
in

0 commit comments

Comments
 (0)