Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions spec/Candid.md
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ not (<datatype> <: opt <datatype'>)
---------------------------------
opt <datatype> <: opt <datatype'>

not (null <: <datatype>)
not (null <: <datatype'>)
not (<datatype> <: <datatype'>)
---------------------------------
opt <datatype> <: opt <datatype'>
Expand Down Expand Up @@ -915,7 +915,7 @@ C[vec <t> <: vec <t'>]( vec { <v>;* } ) = vec { C[<t> <: <t'>](<v>);* }

#### Options

The null type coerces into any option type:
The null type and the reserved type coerce into any option type:
```
C[null <: opt <t>](null) = null
```
Expand All @@ -927,15 +927,20 @@ C[opt <t> <: opt <t'>](opt <v>) = opt C[<t> <: <t'>](v) if <t> <: <t'>
C[opt <t> <: opt <t'>](opt <v>) = null if not(<t> <: <t'>)
```

NOTE: These rules above imply that a Candid decoder has to be able to decide the subtyping relation at runtime.
Coercing a non-null, non-optional and non-reserved type at an option type treats it as an optional value, if it has a suitable type:
```
C[<t> <: opt <t'>](<v>) = opt C[<t> <: <t'>](v) if not (null <: <t'>) and <t> <: <t'>
```

Coercing a non-null, non-optional and non-reserved value at an option type treats it as an optional value:
Any other type goes to `null`:
```
C[<t> <: opt <t'>](<v>) = opt C[<t> <: <t'>](v) if not (null <: <t>) and <t> <: <t'>
C[<t> <: opt <t'>](_) = null if not (null <: <t>) and not (<t> <: <t'>)
C[reserved <: opt <t'>](_) = null
C[reserved <: opt <t>](_) = null
C[<t> <: opt <t'>](_) = null if not (null <: <t'>) and not (<t> <: <t'>)
C[<t> <: opt <t'>](_) = null if null <: <t'> and not (null <: <t>)
```

NOTE: These rules above imply that a Candid decoder has to be able to decide the subtyping relation at runtime.

#### Records

In the following rule:
Expand Down