Skip to content

Commit cd34685

Browse files
authored
flambda-backend: Typedtree module unpacks: Incorporate upstream feedback (#1288)
* Incorporate garrigue's comment It's closer to the old impl to check let-defs for scope escape rather than only let-bound vars. We might as well continue to do that. * Respond to more of garrigue's comments * Remove global state for typechecking patterns (#1281) * Remove global state for typechecking patterns * These comments can go * Two copies of `type_pat_state` when checking or-patterns * Fix bug where `pattern_force` was dropped in or-patterns * Respond to review * remove the (we believe) unneeded call to generalize_structure
1 parent c0482d3 commit cd34685

File tree

5 files changed

+259
-164
lines changed

5 files changed

+259
-164
lines changed

testsuite/tests/typing-fstclassmod/scope_escape.ml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,14 @@ and (module A : S) =
4040
in
4141
();;
4242
[%%expect{|
43-
Line 1, characters 8-9:
44-
1 | let rec k =
45-
^
46-
Error: This pattern matches values of type (module S with type t = A.t)
47-
but a pattern was expected which matches values of type 'a
43+
Lines 2-6, characters 2-22:
44+
2 | ..let (module K : S with type t = A.t) = k in
45+
3 | (module struct
46+
4 | type t = K.t
47+
5 | end : S
48+
6 | with type t = K.t)
49+
Error: This expression has type (module S with type t = A.t)
50+
but an expression was expected of type 'a
4851
The type constructor A.t would escape its scope
4952
|}];;
5053

testsuite/tests/typing-objects/Tests.ml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -779,6 +779,14 @@ Error: This expression has type 'a t but an expression was expected of type
779779
'a
780780
The type variable 'a occurs inside 'a t
781781
|}];;
782+
fun ((x : 'a) | (x : 'a t)) -> ();;
783+
[%%expect{|
784+
Line 1, characters 10-12:
785+
1 | fun ((x : 'a) | (x : 'a t)) -> ();;
786+
^^
787+
Error: This type 'a t should be an instance of type 'a
788+
The type variable 'a occurs inside 'a t
789+
|}];;
782790
type 'a t = < x : 'a >;;
783791
[%%expect{|
784792
type 'a t = < x : 'a >
@@ -795,6 +803,14 @@ Line 1, characters 18-26:
795803
Warning 10 [non-unit-statement]: this expression should have type unit.
796804
- : ('a t as 'a) t -> unit = <fun>
797805
|}];;
806+
fun ((x : 'a) | (x : 'a t)) -> ();;
807+
[%%expect{|
808+
Line 1, characters 17-18:
809+
1 | fun ((x : 'a) | (x : 'a t)) -> ();;
810+
^
811+
Warning 12 [redundant-subpat]: this sub-pattern is unused.
812+
- : ('a t as 'a) -> unit = <fun>
813+
|}];;
798814

799815
class ['a] c () = object
800816
constraint 'a = < .. > -> unit

typing/typeclass.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ and class_expr_aux cl_num val_env met_env virt self_scope scl =
12191219
in
12201220
let partial =
12211221
let dummy = type_exp val_env (Ast_helper.Exp.unreachable ()) in
1222-
Typecore.check_partial Modules_rejected val_env pat.pat_type pat.pat_loc
1222+
Typecore.check_partial val_env pat.pat_type pat.pat_loc
12231223
[{c_lhs = pat; c_guard = None; c_rhs = dummy}]
12241224
in
12251225
let val_env' = Env.add_lock Alloc_mode.global val_env' in

0 commit comments

Comments
 (0)