Skip to content

Commit 79c6926

Browse files
committed
Fix
1 parent d371fb4 commit 79c6926

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -535,36 +535,61 @@ 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

541546
let u = fun (type unused) -> ()
542547
[%%expect {|
543-
Line 1, characters 8-31:
548+
Line 1, characters 18-24:
544549
1 | let u = fun (type unused) -> ()
545-
^^^^^^^^^^^^^^^^^^^^^^^
550+
^^^^^^
546551
Warning 34 [unused-type-declaration]: unused type unused.
547552

548553
val u : unit = ()
549554
|}]
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

556566
let f = fun (type unused) x -> x
557567
[%%expect {|
568+
Line 1, characters 18-24:
569+
1 | let f = fun (type unused) x -> x
570+
^^^^^^
571+
Warning 34 [unused-type-declaration]: unused type unused.
572+
558573
val f : 'a -> 'a = <fun>
559574
|}]
560575

561576
let f (type used unused) (x : used) = x
562577
[%%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+
563583
val f : 'used -> 'used = <fun>
564584
|}]
565585

566586
let f = fun (type used unused) (x : used) -> x
567587

568588
[%%expect{|
589+
Line 1, characters 23-29:
590+
1 | let f = fun (type used unused) (x : used) -> x
591+
^^^^^^
592+
Warning 34 [unused-type-declaration]: unused type unused.
593+
569594
val f : 'used -> 'used = <fun>
570595
|}]

ocaml/typing/typecore.ml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6200,7 +6200,7 @@ and type_expect_
62006200
in
62016201
re { exp with exp_extra =
62026202
(Texp_poly cty, loc, sexp.pexp_attributes) :: exp.exp_extra }
6203-
| Pexp_newtype({txt=name}, sbody) ->
6203+
| Pexp_newtype(name, sbody) ->
62046204
type_newtype_expr ~loc ~env ~expected_mode ~rue ~attributes:sexp.pexp_attributes
62056205
name None sbody
62066206
| Pexp_pack m ->
@@ -6638,7 +6638,7 @@ and type_function
66386638
(* Check everything else in the scope of (type a). *)
66396639
let (params, body, newtypes, contains_gadt, fun_alloc_mode, ret_info),
66406640
exp_type, jkind_annot =
6641-
type_newtype loc env newtype_var.txt jkind_annot (fun env ->
6641+
type_newtype env newtype_var jkind_annot (fun env ->
66426642
let { function_ = exp_type, params, body;
66436643
newtypes; params_contain_gadt = contains_gadt;
66446644
fun_alloc_mode; ret_info;
@@ -8233,9 +8233,10 @@ and type_function_cases_expect
82338233
by the user.
82348234
*)
82358235
and type_newtype
8236-
: type a. _ -> _ -> _ -> _ -> (Env.t -> a * type_expr)
8236+
: type a. _ -> _ -> _ -> (Env.t -> a * type_expr)
82378237
-> a * type_expr * Jkind.annotation option =
8238-
fun loc env name jkind_annot_opt type_body ->
8238+
fun env name jkind_annot_opt type_body ->
8239+
let { txt = name; loc = name_loc } : _ Location.loc = name in
82398240
let jkind, jkind_annot =
82408241
Jkind.of_annotation_option_default ~context:(Newtype_declaration name)
82418242
~default:(Jkind.value ~why:Univar) jkind_annot_opt
@@ -8249,7 +8250,7 @@ and type_newtype
82498250
(* Use [with_local_level] just for scoping *)
82508251
with_local_level begin fun () ->
82518252
(* Create a fake abstract type declaration for name. *)
8252-
let decl = new_local_type ~loc jkind ~jkind_annot in
8253+
let decl = new_local_type ~loc:name_loc jkind ~jkind_annot in
82538254
let scope = create_scope () in
82548255
let (id, new_env) = Env.enter_type ~scope name decl env in
82558256

@@ -8275,15 +8276,15 @@ and type_newtype
82758276
and type_newtype_expr
82768277
~loc ~env ~expected_mode ~rue ~attributes name jkind_annot_opt sbody =
82778278
let body, ety, jkind_annot =
8278-
type_newtype loc env name jkind_annot_opt (fun env ->
8279+
type_newtype env name jkind_annot_opt (fun env ->
82798280
let expr = type_exp env expected_mode sbody in
82808281
expr, expr.exp_type)
82818282
in
82828283
(* non-expansive if the body is non-expansive, so we don't introduce
82838284
any new extra node in the typed AST. *)
82848285
rue { body with exp_loc = loc; exp_type = ety;
82858286
exp_extra =
8286-
(Texp_newtype (name, jkind_annot),
8287+
(Texp_newtype (name.txt, jkind_annot),
82878288
loc, attributes) :: body.exp_extra }
82888289

82898290
(* Typing of let bindings *)
@@ -9166,7 +9167,7 @@ and type_jkind_expr
91669167
~loc ~env ~expected_mode ~ty_expected:_ ~explanation:_ ~rue ~attributes
91679168
: Jane_syntax.Layouts.expression -> _ = function
91689169
| Lexp_constant x -> type_unboxed_constant ~loc ~env ~rue ~attributes x
9169-
| Lexp_newtype ({txt=name}, jkind_annot, sbody) ->
9170+
| Lexp_newtype (name, jkind_annot, sbody) ->
91709171
type_newtype_expr ~loc ~env ~expected_mode ~rue ~attributes
91719172
name (Some jkind_annot) sbody
91729173

0 commit comments

Comments
 (0)