Skip to content

Commit

Permalink
Support value_or_null in list and option (#3623)
Browse files Browse the repository at this point in the history
* `value_or_null` arguments to `list` and `option`

* Tests

* Accept tests

---------

Co-authored-by: Diana Kalinichenko <[email protected]>
  • Loading branch information
dkalinichenko-js and d-kalinichenko authored Feb 25, 2025
1 parent ffcee0c commit 13b14be
Show file tree
Hide file tree
Showing 21 changed files with 396 additions and 192 deletions.
16 changes: 8 additions & 8 deletions testsuite/tests/typing-layouts-bits32/parsing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,47 @@ type t = int32# list;;
Line 1, characters 9-15:
1 | type t = int32# list;;
^^^^^^
Error: This type "int32#" should be an instance of type "('a : value)"
Error: This type "int32#" should be an instance of type "('a : value_or_null)"
The layout of int32# is bits32
because it is the primitive type int32#.
But the layout of int32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

let f (_ : int32# list) = ();;
[%%expect {|
Line 1, characters 11-17:
1 | let f (_ : int32# list) = ();;
^^^^^^
Error: This type "int32#" should be an instance of type "('a : value)"
Error: This type "int32#" should be an instance of type "('a : value_or_null)"
The layout of int32# is bits32
because it is the primitive type int32#.
But the layout of int32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C of int32# list;;
[%%expect {|
Line 1, characters 14-20:
1 | type t = C of int32# list;;
^^^^^^
Error: This type "int32#" should be an instance of type "('a : value)"
Error: This type "int32#" should be an instance of type "('a : value_or_null)"
The layout of int32# is bits32
because it is the primitive type int32#.
But the layout of int32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C : int32# list -> t;;
[%%expect {|
Line 1, characters 13-19:
1 | type t = C : int32# list -> t;;
^^^^^^
Error: This type "int32#" should be an instance of type "('a : value)"
Error: This type "int32#" should be an instance of type "('a : value_or_null)"
The layout of int32# is bits32
because it is the primitive type int32#.
But the layout of int32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

(* Syntax: int32#c
Expand Down
16 changes: 8 additions & 8 deletions testsuite/tests/typing-layouts-bits64/parsing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,47 @@ type t = int64# list;;
Line 1, characters 9-15:
1 | type t = int64# list;;
^^^^^^
Error: This type "int64#" should be an instance of type "('a : value)"
Error: This type "int64#" should be an instance of type "('a : value_or_null)"
The layout of int64# is bits64
because it is the primitive type int64#.
But the layout of int64# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

let f (_ : int64# list) = ();;
[%%expect {|
Line 1, characters 11-17:
1 | let f (_ : int64# list) = ();;
^^^^^^
Error: This type "int64#" should be an instance of type "('a : value)"
Error: This type "int64#" should be an instance of type "('a : value_or_null)"
The layout of int64# is bits64
because it is the primitive type int64#.
But the layout of int64# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C of int64# list;;
[%%expect {|
Line 1, characters 14-20:
1 | type t = C of int64# list;;
^^^^^^
Error: This type "int64#" should be an instance of type "('a : value)"
Error: This type "int64#" should be an instance of type "('a : value_or_null)"
The layout of int64# is bits64
because it is the primitive type int64#.
But the layout of int64# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C : int64# list -> t;;
[%%expect {|
Line 1, characters 13-19:
1 | type t = C : int64# list -> t;;
^^^^^^
Error: This type "int64#" should be an instance of type "('a : value)"
Error: This type "int64#" should be an instance of type "('a : value_or_null)"
The layout of int64# is bits64
because it is the primitive type int64#.
But the layout of int64# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

(* Syntax: int64#c
Expand Down
4 changes: 2 additions & 2 deletions testsuite/tests/typing-layouts-err-msg/value.ml
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,11 @@ Line 1, characters 21-22:
1 | let f (x: t_void) = [x]
^
Error: This expression has type "t_void" but an expression was expected of type
"('a : value)"
"('a : value_or_null)"
The layout of t_void is void
because of the definition of t_void at line 6, characters 0-19.
But the layout of t_void must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

(* Tuple *)
Expand Down
16 changes: 8 additions & 8 deletions testsuite/tests/typing-layouts-float32/parsing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,47 +37,47 @@ type t = float32# list;;
Line 1, characters 9-17:
1 | type t = float32# list;;
^^^^^^^^
Error: This type "float32#" should be an instance of type "('a : value)"
Error: This type "float32#" should be an instance of type "('a : value_or_null)"
The layout of float32# is float32
because it is the primitive type float32#.
But the layout of float32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

let f (_ : float32# list) = ();;
[%%expect {|
Line 1, characters 11-19:
1 | let f (_ : float32# list) = ();;
^^^^^^^^
Error: This type "float32#" should be an instance of type "('a : value)"
Error: This type "float32#" should be an instance of type "('a : value_or_null)"
The layout of float32# is float32
because it is the primitive type float32#.
But the layout of float32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C of float32# list;;
[%%expect {|
Line 1, characters 14-22:
1 | type t = C of float32# list;;
^^^^^^^^
Error: This type "float32#" should be an instance of type "('a : value)"
Error: This type "float32#" should be an instance of type "('a : value_or_null)"
The layout of float32# is float32
because it is the primitive type float32#.
But the layout of float32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C : float32# list -> t;;
[%%expect {|
Line 1, characters 13-21:
1 | type t = C : float32# list -> t;;
^^^^^^^^
Error: This type "float32#" should be an instance of type "('a : value)"
Error: This type "float32#" should be an instance of type "('a : value_or_null)"
The layout of float32# is float32
because it is the primitive type float32#.
But the layout of float32# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

(* Syntax: float32#c
Expand Down
16 changes: 8 additions & 8 deletions testsuite/tests/typing-layouts-float64/parsing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,47 @@ type t = float# list;;
Line 1, characters 9-15:
1 | type t = float# list;;
^^^^^^
Error: This type "float#" should be an instance of type "('a : value)"
Error: This type "float#" should be an instance of type "('a : value_or_null)"
The layout of float# is float64
because it is the primitive type float#.
But the layout of float# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

let f (_ : float# list) = ();;
[%%expect {|
Line 1, characters 11-17:
1 | let f (_ : float# list) = ();;
^^^^^^
Error: This type "float#" should be an instance of type "('a : value)"
Error: This type "float#" should be an instance of type "('a : value_or_null)"
The layout of float# is float64
because it is the primitive type float#.
But the layout of float# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C of float# list;;
[%%expect {|
Line 1, characters 14-20:
1 | type t = C of float# list;;
^^^^^^
Error: This type "float#" should be an instance of type "('a : value)"
Error: This type "float#" should be an instance of type "('a : value_or_null)"
The layout of float# is float64
because it is the primitive type float#.
But the layout of float# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

type t = C : float# list -> t;;
[%%expect {|
Line 1, characters 13-19:
1 | type t = C : float# list -> t;;
^^^^^^
Error: This type "float#" should be an instance of type "('a : value)"
Error: This type "float#" should be an instance of type "('a : value_or_null)"
The layout of float# is float64
because it is the primitive type float#.
But the layout of float# must be a sublayout of value
because the type argument of list has layout value.
because the type argument of list has layout value_or_null.
|}];;

(* Syntax: float#c
Expand Down
71 changes: 0 additions & 71 deletions testsuite/tests/typing-layouts-or-null/array.ml

This file was deleted.

Loading

0 comments on commit 13b14be

Please sign in to comment.