Skip to content

Commit

Permalink
Add recursive modules tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rtjoa committed Dec 26, 2024
1 parent d5f5a5a commit 5b55d46
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions testsuite/tests/typing-layouts-unboxed-records/recursive.ml
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,47 @@ Line 1, characters 0-25:
Error: The definition of "bad" is recursive without boxing:
"bad" contains "bad"
|}]

(* We actually can create singleton recursive unboxed record types,
through recursive modules *)

module F (X : sig type t end) = struct
type u = #{ u : X.t }
end

module rec M : sig
type u
type t = u
end = struct
include F(M)
type t = u
end
[%%expect{|
module F : functor (X : sig type t end) -> sig type u = #{ u : X.t; } end
module rec M : sig type u type t = u end
|}]

module F (X : sig
type u
type t = #{ u : u }
end) = struct
type u = X.t = #{ u : X.u }
end

module rec M : sig
type u
type t = #{ u : u }
end = struct
include F(M)
type t = #{ u : u }
let rec u = #{ u }
end
[%%expect{|
module F :
functor (X : sig type u type t = #{ u : u; } end) ->
sig type u = X.t = #{ u : X.u; } end
Line 14, characters 14-20:
14 | let rec u = #{ u }
^^^^^^
Error: This kind of expression is not allowed as right-hand side of "let rec"
|}]

0 comments on commit 5b55d46

Please sign in to comment.