Skip to content

Commit 287030c

Browse files
committed
Add nullable types
Fixed #196.
1 parent 9cf8b20 commit 287030c

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

spec/13-functions.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ return-type:
7777
':' 'void'
7878
7979
type-declaration:
80+
'?'? base-type-declaration
81+
82+
base-type-declaration:
8083
'array'
8184
'callable'
8285
'iterable'
@@ -123,6 +126,9 @@ default-argument-specifier:
123126
: void
124127

125128
<i id="grammar-type-declaration">type-declaration:</i>
129+
?<sub>opt</sub> <i><a href="#grammar-base-type-declaration">base-type-declaration</a></i>
130+
131+
<i id="grammar-base-type-declaration">base-type-declaration:</i>
126132
array
127133
callable
128134
iterable
@@ -218,7 +224,9 @@ Parameters typed with *scalar-type* are accepted if they pass the type check for
218224
as [described below](#type-check-modes). Once the checks have been passed, the parameter types are always of the scalar type
219225
specified (or `NULL` if `NULL` is allowed).
220226

221-
If a parameter has a type declaration, `NULL` is not accepted unless it has a default value that evaluates to `NULL`.
227+
If a parameter has a type declaration, `NULL` is not accepted unless the
228+
type is nullable. A type is nullable if it is prefixed with `?` or if the
229+
parameter has a default value that evaluates to `NULL`.
222230

223231
The default value for a typed parameter must be of the type specified, or `NULL`,
224232
and conversion is not be performed for defaults, regardless of the mode.

spec/19-grammar.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -929,6 +929,9 @@ The grammar notation is described in [Grammars section](09-lexical-structure.md#
929929
: void
930930

931931
<i id="grammar-type-declaration">type-declaration:</i>
932+
?<sub>opt</sub> <i><a href="#grammar-base-type-declaration">base-type-declaration</a></i>
933+
934+
<i id="grammar-base-type-declaration">base-type-declaration:</i>
932935
array
933936
callable
934937
iterable

0 commit comments

Comments
 (0)