Skip to content

Commit aba14c2

Browse files
authored
flambda-backend: Check for value in polymorphic variant argument (#1482)
1 parent 0a20dfb commit aba14c2

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

testsuite/tests/typing-layouts/basics.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,9 @@ Error: Layout void is used here, but the appropriate layouts extension is not en
305305

306306
(* CR layouts: This test moves to [basics_alpha.ml] as it needs a non-value
307307
sort. Bring back here when we have one enabled by default. *)
308+
309+
(*********************************************************)
310+
(* Test 32: Polymorphic variant constructors take values *)
311+
312+
(* CR layouts: This test moves to [basics_alpha.ml] as it needs a non-value
313+
sort. Bring back here when we have one enabled by default. *)

testsuite/tests/typing-layouts/basics_alpha.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,3 +1462,17 @@ Error: This type ('a : value) should be an instance of type ('a0 : void)
14621462
the type definition if we're not allowing `void` things in structures).
14631463
This bug is a goof at the top of Typecore.build_or_pat;
14641464
there is another CR layouts there. *)
1465+
1466+
(*********************************************************)
1467+
(* Test 32: Polymorphic variant constructors take values *)
1468+
1469+
let f _ = `Mk (assert false : t_void)
1470+
1471+
[%%expect{|
1472+
Line 1, characters 14-37:
1473+
1 | let f _ = `Mk (assert false : t_void)
1474+
^^^^^^^^^^^^^^^^^^^^^^^
1475+
Error: This expression has type t_void but an expression was expected of type
1476+
('a : value)
1477+
t_void has layout void, which is not a sublayout of value.
1478+
|}]

testsuite/tests/typing-layouts/basics_beta.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,9 @@ Error: Layout void is used here, but the appropriate layouts extension is not en
511511

512512
(* CR layouts: This test moves to [basics_alpha.ml] as it needs a non-value
513513
sort. Bring back here when we have one. *)
514+
515+
(*********************************************************)
516+
(* Test 32: Polymorphic variant constructors take values *)
517+
518+
(* CR layouts: This test moves to [basics_alpha.ml] as it needs a non-value
519+
sort. Bring back here when we have one. *)

typing/typecore.ml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4557,7 +4557,12 @@ and type_expect_
45574557
let arg = match sarg with
45584558
| None -> None
45594559
| Some sarg ->
4560-
let arg = type_exp env argument_mode sarg in
4560+
let ty_expected =
4561+
newvar (Layout.value ~why:Polymorphic_variant_field)
4562+
in
4563+
let arg =
4564+
type_expect env argument_mode sarg (mk_expected ty_expected)
4565+
in
45614566
let alloc_mode = register_allocation expected_mode in
45624567
Some (arg, alloc_mode)
45634568
in

0 commit comments

Comments
 (0)