Skip to content

Commit 5cc3938

Browse files
Better error messages for GADTs and int overflows (#7830)
* Better error messages for GADTs and int overflows * Add test fixtures
1 parent 2dc0103 commit 5cc3938

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

compiler/frontend/bs_ast_invariant.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ let emit_external_warnings : iterator =
8585
( Nonrecursive,
8686
[{ptype_kind = Ptype_variant ({pcd_res = Some _} :: _)}] ) ->
8787
Location.raise_errorf ~loc:str_item.pstr_loc
88-
"GADT has to be recursive types, please try `type rec'"
88+
"GADTs require recursive type syntax.\n\
89+
Please define your type using `type rec` instead of `type`.\n\
90+
Example: type rec t = ..."
8991
| _ -> super.structure_item self str_item);
9092
expr =
9193
(fun self ({pexp_loc = loc} as a) ->
@@ -95,7 +97,8 @@ let emit_external_warnings : iterator =
9597
try ignore (Ext_string.hash_number_as_i32_exn s : int32)
9698
with _ ->
9799
Location.raise_errorf ~loc
98-
"This number is too large to cause int overlow")
100+
"Integer literal exceeds int32 range. Use float or BigInt if \
101+
larger values are required.")
99102
| _ -> super.expr self a);
100103
label_declaration =
101104
(fun self lbl ->
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/gadt_rec_missing.res:4:1-8:27
4+
5+
2 │ type daylight
6+
3 │
7+
4 │ type timezone<_> =
8+
5 │  | EST: timezone<standard>
9+
6 │  | EDT: timezone<daylight>
10+
7 │  | CST: timezone<standard>
11+
8 │  | CDT: timezone<daylight>
12+
9 │
13+
14+
GADTs require recursive type syntax.
15+
Please define your type using `type rec` instead of `type`.
16+
Example: type rec t = ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
We've found a bug for you!
3+
/.../fixtures/polyvariant_int_too_large.res:1:9-29
4+
5+
1 │ let x = #12345678901234567890
6+
2 │
7+
8+
Integer literal exceeds int32 range. Use float or BigInt if larger values are required.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
type standard
2+
type daylight
3+
4+
type timezone<_> =
5+
| EST: timezone<standard>
6+
| EDT: timezone<daylight>
7+
| CST: timezone<standard>
8+
| CDT: timezone<daylight>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
let x = #12345678901234567890

0 commit comments

Comments
 (0)