Skip to content

Commit c853515

Browse files
committed
force open
1 parent abc843d commit c853515

File tree

5 files changed

+81
-3
lines changed

5 files changed

+81
-3
lines changed

compiler/ext/warnings.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,10 @@ let message = function
432432
^ "\nThe first one was selected. Disambiguate if this is wrong."
433433
| Nonoptional_label s -> "the label " ^ s ^ " is not optional."
434434
| Open_shadow_identifier (kind, s) ->
435-
(* TODO(actions) Force open *)
436435
Printf.sprintf
437436
"this open statement shadows the %s identifier %s (which is later used)"
438437
kind s
439438
| Open_shadow_label_constructor (kind, s) ->
440-
(* TODO(actions) Force open *)
441439
Printf.sprintf "this open statement shadows the %s %s (which is later used)"
442440
kind s
443441
| Attribute_payload (a, s) ->

compiler/ml/cmt_utils.ml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type action_type =
1616
| RemoveUnusedType
1717
| RemoveUnusedModule
1818
| RemoveRecFlag
19+
| ForceOpen
1920

2021
(* TODO:
2122
- Unused var in patterns (and aliases )*)
@@ -51,6 +52,7 @@ let action_to_string = function
5152
Printf.sprintf "RewriteIdent(%s)"
5253
(Longident.flatten new_ident |> String.concat ".")
5354
| RemoveRecFlag -> "RemoveRecFlag"
55+
| ForceOpen -> "ForceOpen"
5456

5557
let _add_possible_action : (cmt_action -> unit) ref = ref (fun _ -> ())
5658
let add_possible_action action = !_add_possible_action action
@@ -87,6 +89,8 @@ let emit_possible_actions_from_warning loc w =
8789
| Unused_rec_flag ->
8890
add_possible_action
8991
{loc; action = RemoveRecFlag; description = "Remove rec flag"}
92+
| Open_shadow_identifier _ | Open_shadow_label_constructor _ ->
93+
add_possible_action {loc; action = ForceOpen; description = "Force open"}
9094
| _ -> ()
9195

9296
let _ =
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
type person = {
2+
name: string,
3+
age: int,
4+
}
5+
6+
module X = {
7+
let ff = 15
8+
}
9+
10+
let ff = 16
11+
12+
open! X
13+
14+
let f2 = ff
15+
16+
module RecordExample = {
17+
type t = {
18+
name: string,
19+
age: int,
20+
}
21+
let person = {name: "John", age: 30}
22+
}
23+
24+
open! RecordExample
25+
26+
let p = {name: "Jane", age: 25}
27+
28+
/* === AVAILABLE ACTIONS:
29+
- ForceOpen - Force open
30+
- ForceOpen - Force open
31+
- ForceOpen - Force open
32+
*/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
type person = {
2+
name: string,
3+
age: int,
4+
}
5+
6+
module X = {
7+
let ff = 15
8+
}
9+
10+
let ff = 16
11+
12+
open X
13+
14+
let f2 = ff
15+
16+
module RecordExample = {
17+
type t = {
18+
name: string,
19+
age: int,
20+
}
21+
let person = {name: "John", age: 30}
22+
}
23+
24+
open RecordExample
25+
26+
let p = {name: "Jane", age: 25}

tools/src/tools.ml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1308,7 +1308,24 @@ module Actions = struct
13081308
| _ -> None)
13091309
actions
13101310
in
1311+
let force_open_action_locs =
1312+
List.filter_map
1313+
(fun (action : Cmt_utils.cmt_action) ->
1314+
match action.action with
1315+
| ForceOpen -> Some action.loc
1316+
| _ -> None)
1317+
actions
1318+
in
13111319
match str_item.pstr_desc with
1320+
| Pstr_open ({popen_override = Fresh} as open_desc)
1321+
when List.mem str_item.pstr_loc force_open_action_locs ->
1322+
let str_item =
1323+
Ast_mapper.default_mapper.structure_item mapper str_item
1324+
in
1325+
{
1326+
str_item with
1327+
pstr_desc = Pstr_open {open_desc with popen_override = Override};
1328+
}
13121329
| Pstr_value (Recursive, ({pvb_pat = {ppat_loc}} :: _ as bindings))
13131330
when List.mem ppat_loc remove_rec_flag_action_locs ->
13141331
let str_item =
@@ -1663,7 +1680,8 @@ module Actions = struct
16631680
List.mem "RemoveUnusedVariable" filter
16641681
| RemoveUnusedType -> List.mem "RemoveUnusedType" filter
16651682
| RemoveUnusedModule -> List.mem "RemoveUnusedModule" filter
1666-
| RemoveRecFlag -> List.mem "RemoveRecFlag" filter)
1683+
| RemoveRecFlag -> List.mem "RemoveRecFlag" filter
1684+
| ForceOpen -> List.mem "ForceOpen" filter)
16671685
in
16681686
match applyActionsToFile path possible_actions with
16691687
| Ok applied ->

0 commit comments

Comments
 (0)