Skip to content

Commit a5420aa

Browse files
authored
Merge pull request #4482 from BuckleScript/not_allow_unit
not allowing unit to be redefined, refined error message
2 parents dc27403 + be07a1f commit a5420aa

File tree

8 files changed

+102
-105
lines changed

8 files changed

+102
-105
lines changed

jscomp/syntax/bs_ast_invariant.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,12 @@ let emit_external_warnings : iterator=
117117
);
118118
default_iterator.label_declaration self lbl
119119
);
120-
constructor_declaration = (fun self ({pcd_name} as ctr) ->
121-
(match pcd_name.txt with
120+
constructor_declaration = (fun self ({pcd_name = {txt;loc}} as ctr) ->
121+
(match txt with
122122
| "false"
123-
| "true" ->
124-
Location.raise_errorf ~loc:pcd_name.loc "true/false can not be redefined "
123+
| "true"
124+
| "()" ->
125+
Location.raise_errorf ~loc:loc "%s can not be redefined " txt
125126
| _ -> ());
126127
default_iterator.constructor_declaration self ctr
127128
);

jscomp/test/debug_tmp.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1 @@
1-
'use strict';
2-
3-
4-
throw {
5-
RE_EXN_ID: "Not_found",
6-
Error: new Error()
7-
};
8-
9-
/* Not a pure module */
1+
/* This output is empty. Its source's type definitions, externals and/or unused code got optimized away. */

jscomp/test/debug_tmp.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99
|]
1010
}]
1111

12-
let () = raise Not_found
12+

jscomp/test/unit_undefined_test.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let fx () = ()
3030
let u0 (x : unit) = Some x
3131

3232
let u1 = Some ()
33-
type t = ()
33+
type t = unit
3434

3535
let u2 (x : t) = Some x
3636
let u3 : t option = Some ()

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401616,11 +401616,12 @@ let emit_external_warnings : iterator=
401616401616
);
401617401617
default_iterator.label_declaration self lbl
401618401618
);
401619-
constructor_declaration = (fun self ({pcd_name} as ctr) ->
401620-
(match pcd_name.txt with
401619+
constructor_declaration = (fun self ({pcd_name = {txt;loc}} as ctr) ->
401620+
(match txt with
401621401621
| "false"
401622-
| "true" ->
401623-
Location.raise_errorf ~loc:pcd_name.loc "true/false can not be redefined "
401622+
| "true"
401623+
| "()" ->
401624+
Location.raise_errorf ~loc:loc "%s can not be redefined " txt
401624401625
| _ -> ());
401625401626
default_iterator.constructor_declaration self ctr
401626401627
);

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401616,11 +401616,12 @@ let emit_external_warnings : iterator=
401616401616
);
401617401617
default_iterator.label_declaration self lbl
401618401618
);
401619-
constructor_declaration = (fun self ({pcd_name} as ctr) ->
401620-
(match pcd_name.txt with
401619+
constructor_declaration = (fun self ({pcd_name = {txt;loc}} as ctr) ->
401620+
(match txt with
401621401621
| "false"
401622-
| "true" ->
401623-
Location.raise_errorf ~loc:pcd_name.loc "true/false can not be redefined "
401622+
| "true"
401623+
| "()" ->
401624+
Location.raise_errorf ~loc:loc "%s can not be redefined " txt
401624401625
| _ -> ());
401625401626
default_iterator.constructor_declaration self ctr
401626401627
);

lib/4.06.1/unstable/native_ppx.ml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15082,11 +15082,12 @@ let emit_external_warnings : iterator=
1508215082
);
1508315083
default_iterator.label_declaration self lbl
1508415084
);
15085-
constructor_declaration = (fun self ({pcd_name} as ctr) ->
15086-
(match pcd_name.txt with
15085+
constructor_declaration = (fun self ({pcd_name = {txt;loc}} as ctr) ->
15086+
(match txt with
1508715087
| "false"
15088-
| "true" ->
15089-
Location.raise_errorf ~loc:pcd_name.loc "true/false can not be redefined "
15088+
| "true"
15089+
| "()" ->
15090+
Location.raise_errorf ~loc:loc "%s can not be redefined " txt
1509015091
| _ -> ());
1509115092
default_iterator.constructor_declaration self ctr
1509215093
);

0 commit comments

Comments
 (0)