summaryrefslogtreecommitdiff
path: root/testsuite/tests/letrec-check/unboxed.ml
blob: c048d122d97d93bec3add3ea4e3f5d78a3d1723d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
(* TEST
   * expect
*)

type r = R of r list [@@unboxed]
let rec a = R [a];;
[%%expect{|
type r = R of r list [@@unboxed]
val a : r = R [<cycle>]
|}];;


type t = {x: int64} [@@unboxed]
let rec x = {x = y} and y = 3L;;
[%%expect{|
type t = { x : int64; } [@@unboxed]
Line 2, characters 12-19:
2 | let rec x = {x = y} and y = 3L;;
                ^^^^^^^
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;

type r = A of r [@@unboxed]
let rec y = A y;;
[%%expect{|
type r = A of r [@@unboxed]
Line 2, characters 12-15:
2 | let rec y = A y;;
                ^^^
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;

(* This test is not allowed if 'a' is unboxed, but should be accepted
   as written *)
type a = {a: b}
and b = X of a | Y

let rec a =
  {a=
    (if Sys.opaque_identity true then
       X a
     else
       Y)};;
[%%expect{|
type a = { a : b; }
and b = X of a | Y
val a : a = {a = X <cycle>}
|}];;

type a = {a: b }[@@unboxed]
and b = X of a | Y

let rec a =
  {a=
    (if Sys.opaque_identity true then
       X a
     else
       Y)};;
[%%expect{|
type a = { a : b; } [@@unboxed]
and b = X of a | Y
Line 5, characters 2-75:
5 | ..{a=
  |     (if Sys.opaque_identity true then
  |        X a
  |      else
9 |        Y)}..
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;

(* This test is not allowed if 'c' is unboxed, but should be accepted
   as written *)
type d = D of e
and e = V of d | W;;
[%%expect{|
type d = D of e
and e = V of d | W
|}];;

let rec d =
  D
    (if Sys.opaque_identity true then
       V d
     else
       W);;
[%%expect{|
val d : d = D (V <cycle>)
|}];;

type d = D of e [@@unboxed]
and e = V of d | W;;

let rec d =
  D
    (if Sys.opaque_identity true then
       V d
     else
       W);;
[%%expect{|
type d = D of e [@@unboxed]
and e = V of d | W
Line 5, characters 2-72:
5 | ..D
  |     (if Sys.opaque_identity true then
  |        V d
  |      else
9 |        W)..
Error: This kind of expression is not allowed as right-hand side of `let rec'
|}];;