From c5fc9cfe2ed2b26b8ea3887a7a7577ffab89e1af Mon Sep 17 00:00:00 2001 From: Ryan Tjoa Date: Thu, 26 Dec 2024 18:33:35 -0500 Subject: [PATCH] Add example of conservatively rejected recursion --- .../typing-layouts-unboxed-records/recursive.ml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testsuite/tests/typing-layouts-unboxed-records/recursive.ml b/testsuite/tests/typing-layouts-unboxed-records/recursive.ml index 966a22c7032..57e67e9ef97 100644 --- a/testsuite/tests/typing-layouts-unboxed-records/recursive.ml +++ b/testsuite/tests/typing-layouts-unboxed-records/recursive.ml @@ -247,6 +247,20 @@ Error: Unboxed record element types must have a representable layout. (***************************************) (* Singleton recursive unboxed records *) +(* The check is conservative; we could allow this*) + +type 'a safe = #{ a : 'a } +type x = int safe safe +[%%expect{| +type 'a safe = #{ a : 'a; } +Line 2, characters 0-22: +2 | type x = int safe safe + ^^^^^^^^^^^^^^^^^^^^^^ +Error: The definition of "x" is recursive without boxing: + "x" = "int safe safe", + "int safe safe" contains "int safe" +|}] + (* We could allow these, as although they have unguarded recursion, they are finite size (thanks to the fact that we represent single-field records as the layout of the field rather than as a singleton product).