| ... | ... | @@ -2785,6 +2785,16 @@ test "implicitly cast to const pointer" { |
| 2785 | 2785 | use the C calling convention may pass structs and unions by value. |
| 2786 | 2786 | </p> |
| 2787 | 2787 | {#header_close#} |
| 2788 | {#header_open|Function Reflection#} |
| 2789 | {#code_begin|test#} |
| 2790 | const assert = @import("std").debug.assert; |
| 2791 | |
| 2792 | test "fn reflection" { |
| 2793 | assert(@typeOf(assert).ReturnType == void); |
| 2794 | assert(@typeOf(assert).is_var_args == false); |
| 2795 | } |
| 2796 | {#code_end#} |
| 2797 | {#header_close#} |
| 2788 | 2798 | {#header_close#} |
| 2789 | 2799 | {#header_open|Errors#} |
| 2790 | 2800 | <p> |
| ... | ... | @@ -2998,6 +3008,31 @@ fn createFoo(param: i32) %Foo { |
| 2998 | 3008 | </li> |
| 2999 | 3009 | </ul> |
| 3000 | 3010 | {#see_also|defer|if|switch#} |
| 3011 | {#header_open|Error Union Type#} |
| 3012 | <p>An error union is created by putting a <code>%</code> in front of a type. |
| 3013 | You can use compile-time reflection to access the child type of an error union:</p> |
| 3014 | {#code_begin|test#} |
| 3015 | const assert = @import("std").debug.assert; |
| 3016 | |
| 3017 | error SomeError; |
| 3018 | |
| 3019 | test "error union" { |
| 3020 | var foo: %i32 = undefined; |
| 3021 | |
| 3022 | // Implicitly cast from child type of an error union: |
| 3023 | foo = 1234; |
| 3024 | |
| 3025 | // Implicitly cast from an error set: |
| 3026 | foo = error.SomeError; |
| 3027 | |
| 3028 | // Use compile-time reflection to access the child type of an error union: |
| 3029 | comptime assert(@typeOf(foo).Child == i32); |
| 3030 | } |
| 3031 | {#code_end#} |
| 3032 | {#header_close#} |
| 3033 | {#header_open|Error Set Type#} |
| 3034 | <p>TODO</p> |
| 3035 | {#header_close#} |
| 3001 | 3036 | {#header_close#} |
| 3002 | 3037 | {#header_open|Nullables#} |
| 3003 | 3038 | <p> |
| ... | ... | @@ -3099,6 +3134,24 @@ fn doAThing(nullable_foo: ?&Foo) void { |
| 3099 | 3134 | The optimizer can sometimes make better decisions knowing that pointer arguments |
| 3100 | 3135 | cannot be null. |
| 3101 | 3136 | </p> |
| 3137 | {#header_open|Nullable Type#} |
| 3138 | <p>A nullable is created by putting <code>?</code> in front of a type. You can use compile-time |
| 3139 | reflection to access the child type of a nullable:</p> |
| 3140 | {#code_begin|test#} |
| 3141 | const assert = @import("std").debug.assert; |
| 3142 | |
| 3143 | test "nullable type" { |
| 3144 | // Declare a nullable and implicitly cast from null: |
| 3145 | var foo: ?i32 = null; |
| 3146 | |
| 3147 | // Implicitly cast from child type of a nullable |
| 3148 | foo = 1234; |
| 3149 | |
| 3150 | // Use compile-time reflection to access the child type of the nullable: |
| 3151 | comptime assert(@typeOf(foo).Child == i32); |
| 3152 | } |
| 3153 | {#code_end#} |
| 3154 | {#header_close#} |
| 3102 | 3155 | {#header_close#} |
| 3103 | 3156 | {#header_open|Casting#} |
| 3104 | 3157 | <p>TODO: explain implicit vs explicit casting</p> |
| ... | ... | @@ -5731,9 +5784,6 @@ ContainerDecl = option("extern" | "packed") |
| 5731 | 5784 | <li>Together we serve end users.</li> |
| 5732 | 5785 | </ul> |
| 5733 | 5786 | {#header_close#} |
| 5734 | | {#header_open|TODO#} |
| 5735 | | <p>TODO: document changes from a31b23c46ba2a8c28df01adc1aa0b4d878b9a5cf (compile time reflection additions)</p> |
| 5736 | | {#header_close#} |
| 5737 | 5787 | </div> |
| 5738 | 5788 | <script> |
| 5739 | 5789 | /*! highlight.js v9.12.0 | BSD3 License | git.io/hljslicense */ |