| ... | @@ -3602,6 +3602,10 @@ test "implicit cast - invoke a type as a function" { | ... | @@ -3602,6 +3602,10 @@ test "implicit cast - invoke a type as a function" { |
| 3602 | var b = u16(a); | 3602 | var b = u16(a); |
| 3603 | } | 3603 | } |
| 3604 | {#code_end#} | 3604 | {#code_end#} |
| | 3605 | <p> |
| | 3606 | Implicit casts are only allowed when it is completely unambiguous how to get from one type to another, |
| | 3607 | and the transformation is guaranteed to be safe. |
| | 3608 | </p> |
| 3605 | {#header_open|Implicit Cast: Stricter Qualification#} | 3609 | {#header_open|Implicit Cast: Stricter Qualification#} |
| 3606 | <p> | 3610 | <p> |
| 3607 | Values which have the same representation at runtime can be cast to increase the strictness | 3611 | Values which have the same representation at runtime can be cast to increase the strictness |
| ... | @@ -3722,7 +3726,32 @@ test "float widening" { | ... | @@ -3722,7 +3726,32 @@ test "float widening" { |
| 3722 | {#header_close#} | 3726 | {#header_close#} |
| 3723 | | 3727 | |
| 3724 | {#header_open|Explicit Casts#} | 3728 | {#header_open|Explicit Casts#} |
| 3725 | <p>TODO</p> | 3729 | <p> |
| | 3730 | Explicit casts are performed via {#link|Builtin Functions#}. |
| | 3731 | Some explicit casts are safe; some are not. |
| | 3732 | Some explicit casts perform language-level assertions; some do not. |
| | 3733 | Some explicit casts are no-ops at runtime; some are not. |
| | 3734 | </p> |
| | 3735 | <ul> |
| | 3736 | <li>{#link|@bitCast#} - change type but maintain bit representation</li> |
| | 3737 | <li>{#link|@alignCast#} - make a pointer have more alignment</li> |
| | 3738 | <li>{#link|@boolToInt#} - convert true to 1 and false to 0</li> |
| | 3739 | <li>{#link|@bytesToSlice#} - convert a slice of bytes to a slice of another type</li> |
| | 3740 | <li>{#link|@enumToInt#} - obtain the integer tag value of an enum or tagged union</li> |
| | 3741 | <li>{#link|@errSetCast#} - convert to a smaller error set</li> |
| | 3742 | <li>{#link|@errorToInt#} - obtain the integer value of an error code</li> |
| | 3743 | <li>{#link|@floatCast#} - convert a larger float to a smaller float</li> |
| | 3744 | <li>{#link|@floatToInt#} - obtain the integer part of a float value</li> |
| | 3745 | <li>{#link|@intCast#} - convert between integer types</li> |
| | 3746 | <li>{#link|@intToEnum#} - obtain an enum value based on its integer tag value</li> |
| | 3747 | <li>{#link|@intToError#} - obtain an error code based on its integer value</li> |
| | 3748 | <li>{#link|@intToFloat#} - convert an integer to a float value</li> |
| | 3749 | <li>{#link|@intToPtr#} - convert an address to a pointer</li> |
| | 3750 | <li>{#link|@ptrCast#} - convert between pointer types</li> |
| | 3751 | <li>{#link|@ptrToInt#} - obtain the address of a pointer</li> |
| | 3752 | <li>{#link|@sliceToBytes#} - convert a slice of anything to a slice of bytes</li> |
| | 3753 | <li>{#link|@truncate#} - convert between integer types, chopping off bits</li> |
| | 3754 | </ul> |
| 3726 | {#header_close#} | 3755 | {#header_close#} |
| 3727 | | 3756 | |
| 3728 | {#header_open|Peer Type Resolution#} | 3757 | {#header_open|Peer Type Resolution#} |