test_optional_type.zig (368B) - Raw
1 const expect = @import("std").testing.expect; 2 3 test "optional type" { 4 // Declare an optional and coerce from null: 5 var foo: ?i32 = null; 6 7 // Coerce from child type of an optional 8 foo = 1234; 9 10 // Use compile-time reflection to access the child type of the optional: 11 try comptime expect(@typeInfo(@TypeOf(foo)).optional.child == i32); 12 } 13 14 // test