Skip to content

Commit b11c00d

Browse files
committed
Fix
1 parent dbd4c78 commit b11c00d

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

ocaml/testsuite/tests/typing-warnings/unused_types.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,11 @@ module Unused_field_disable_one_warning : sig end
535535

536536
let u (type unused) = ()
537537
[%%expect {|
538+
Line 1, characters 12-18:
539+
1 | let u (type unused) = ()
540+
^^^^^^
541+
Warning 34 [unused-type-declaration]: unused type unused.
542+
538543
val u : unit = ()
539544
|}]
540545

@@ -550,6 +555,11 @@ val u : unit = ()
550555

551556
let f (type unused) x = x
552557
[%%expect {|
558+
Line 1, characters 12-18:
559+
1 | let f (type unused) x = x
560+
^^^^^^
561+
Warning 34 [unused-type-declaration]: unused type unused.
562+
553563
val f : 'a -> 'a = <fun>
554564
|}]
555565

@@ -565,6 +575,11 @@ val f : 'a -> 'a = <fun>
565575

566576
let f (type used unused) (x : used) = x
567577
[%%expect {|
578+
Line 1, characters 17-23:
579+
1 | let f (type used unused) (x : used) = x
580+
^^^^^^
581+
Warning 34 [unused-type-declaration]: unused type unused.
582+
568583
val f : 'used -> 'used = <fun>
569584
|}]
570585

ocaml/typing/typecore.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6226,7 +6226,7 @@ and type_expect_
62266226
in
62276227
re { exp with exp_extra =
62286228
(Texp_poly cty, loc, sexp.pexp_attributes) :: exp.exp_extra }
6229-
| Pexp_newtype({txt=name}, sbody) ->
6229+
| Pexp_newtype(name, sbody) ->
62306230
type_newtype_expr ~loc ~env ~expected_mode ~rue ~attributes:sexp.pexp_attributes
62316231
name None sbody
62326232
| Pexp_pack m ->
@@ -6664,7 +6664,7 @@ and type_function
66646664
(* Check everything else in the scope of (type a). *)
66656665
let (params, body, newtypes, contains_gadt, fun_alloc_mode, ret_info),
66666666
exp_type, jkind_annot =
6667-
type_newtype loc env newtype_var.txt jkind_annot (fun env ->
6667+
type_newtype env newtype_var jkind_annot (fun env ->
66686668
let { function_ = exp_type, params, body;
66696669
newtypes; params_contain_gadt = contains_gadt;
66706670
fun_alloc_mode; ret_info;
@@ -8259,9 +8259,10 @@ and type_function_cases_expect
82598259
by the user.
82608260
*)
82618261
and type_newtype
8262-
: type a. _ -> _ -> _ -> _ -> (Env.t -> a * type_expr)
8262+
: type a. _ -> _ -> _ -> (Env.t -> a * type_expr)
82638263
-> a * type_expr * Jkind.annotation option =
8264-
fun loc env name jkind_annot_opt type_body ->
8264+
fun env name jkind_annot_opt type_body ->
8265+
let { txt = name; loc = name_loc } : _ Location.loc = name in
82658266
let jkind, jkind_annot =
82668267
Jkind.of_annotation_option_default ~context:(Newtype_declaration name)
82678268
~default:(Jkind.value ~why:Univar) jkind_annot_opt
@@ -8275,7 +8276,7 @@ and type_newtype
82758276
(* Use [with_local_level] just for scoping *)
82768277
with_local_level begin fun () ->
82778278
(* Create a fake abstract type declaration for name. *)
8278-
let decl = new_local_type ~loc jkind ~jkind_annot in
8279+
let decl = new_local_type ~loc:name_loc jkind ~jkind_annot in
82798280
let scope = create_scope () in
82808281
let (id, new_env) = Env.enter_type ~scope name decl env in
82818282

@@ -8301,15 +8302,15 @@ and type_newtype
83018302
and type_newtype_expr
83028303
~loc ~env ~expected_mode ~rue ~attributes name jkind_annot_opt sbody =
83038304
let body, ety, jkind_annot =
8304-
type_newtype loc env name jkind_annot_opt (fun env ->
8305+
type_newtype env name jkind_annot_opt (fun env ->
83058306
let expr = type_exp env expected_mode sbody in
83068307
expr, expr.exp_type)
83078308
in
83088309
(* non-expansive if the body is non-expansive, so we don't introduce
83098310
any new extra node in the typed AST. *)
83108311
rue { body with exp_loc = loc; exp_type = ety;
83118312
exp_extra =
8312-
(Texp_newtype (name, jkind_annot),
8313+
(Texp_newtype (name.txt, jkind_annot),
83138314
loc, attributes) :: body.exp_extra }
83148315

83158316
(* Typing of let bindings *)
@@ -9191,7 +9192,7 @@ and type_jkind_expr
91919192
~loc ~env ~expected_mode ~ty_expected:_ ~explanation:_ ~rue ~attributes
91929193
: Jane_syntax.Layouts.expression -> _ = function
91939194
| Lexp_constant x -> type_unboxed_constant ~loc ~env ~rue ~attributes x
9194-
| Lexp_newtype ({txt=name}, jkind_annot, sbody) ->
9195+
| Lexp_newtype (name, jkind_annot, sbody) ->
91959196
type_newtype_expr ~loc ~env ~expected_mode ~rue ~attributes
91969197
name (Some jkind_annot) sbody
91979198

0 commit comments

Comments
 (0)