| author | |
| committer | |
| log | a933a59ced8175a513ff123c3496b1b563d58453 |
| tree | d5a56d76d0a6156a925a86507d27a4025b317890 |
| parent | 6214f66dc108bd34a3ffa1ba5ac7704050a2f156 |
| parent | ec4cd87ed76b47eae9fce95f18ec396aa44f2c0f |
| signature |
add test coverage for fixed stage1 bugs5 files changed, 95 insertions(+), 0 deletions(-)
test/behavior/basic.zig+14| ... | @@ -1143,3 +1143,17 @@ test "orelse coercion as function argument" { | ... | @@ -1143,3 +1143,17 @@ test "orelse coercion as function argument" { |
| 1143 | var foo = Container.init(optional orelse .{}); | 1143 | var foo = Container.init(optional orelse .{}); |
| 1144 | try expect(foo.a.?.start == -1); | 1144 | try expect(foo.a.?.start == -1); |
| 1145 | } | 1145 | } |
| 1146 | |||
| 1147 | test "runtime-known globals initialized with undefined" { | ||
| 1148 | const S = struct { | ||
| 1149 | var array: [10]u32 = [_]u32{ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; | ||
| 1150 | var vp: [*]u32 = undefined; | ||
| 1151 | var s: []u32 = undefined; | ||
| 1152 | }; | ||
| 1153 | |||
| 1154 | S.vp = &S.array; | ||
| 1155 | S.s = S.vp[0..5]; | ||
| 1156 | |||
| 1157 | try expect(S.s[0] == 1); | ||
| 1158 | try expect(S.s[4] == 5); | ||
| 1159 | } |
test/behavior/cast.zig+9| ... | @@ -1568,3 +1568,12 @@ test "@volatileCast without a result location" { | ... | @@ -1568,3 +1568,12 @@ test "@volatileCast without a result location" { |
| 1568 | try expect(@TypeOf(z) == *i32); | 1568 | try expect(@TypeOf(z) == *i32); |
| 1569 | try expect(z.* == 1234); | 1569 | try expect(z.* == 1234); |
| 1570 | } | 1570 | } |
| 1571 | |||
| 1572 | test "coercion from single-item pointer to @as to slice" { | ||
| 1573 | var x: u32 = 1; | ||
| 1574 | |||
| 1575 | // Why the following line gets a compile error? | ||
| 1576 | const t: []u32 = @as(*[1]u32, &x); | ||
| 1577 | |||
| 1578 | try expect(t[0] == 1); | ||
| 1579 | } |
test/behavior/struct.zig+35| ... | @@ -1578,3 +1578,38 @@ test "directly initiating tuple like struct" { | ... | @@ -1578,3 +1578,38 @@ test "directly initiating tuple like struct" { |
| 1578 | const a = struct { u8 }{8}; | 1578 | const a = struct { u8 }{8}; |
| 1579 | try expect(a[0] == 8); | 1579 | try expect(a[0] == 8); |
| 1580 | } | 1580 | } |
| 1581 | |||
| 1582 | test "instantiate struct with comptime field" { | ||
| 1583 | { | ||
| 1584 | var things = struct { | ||
| 1585 | comptime foo: i8 = 1, | ||
| 1586 | }{}; | ||
| 1587 | |||
| 1588 | comptime std.debug.assert(things.foo == 1); | ||
| 1589 | } | ||
| 1590 | |||
| 1591 | { | ||
| 1592 | const T = struct { | ||
| 1593 | comptime foo: i8 = 1, | ||
| 1594 | }; | ||
| 1595 | var things = T{}; | ||
| 1596 | |||
| 1597 | comptime std.debug.assert(things.foo == 1); | ||
| 1598 | } | ||
| 1599 | |||
| 1600 | { | ||
| 1601 | var things: struct { | ||
| 1602 | comptime foo: i8 = 1, | ||
| 1603 | } = .{}; | ||
| 1604 | |||
| 1605 | comptime std.debug.assert(things.foo == 1); | ||
| 1606 | } | ||
| 1607 | |||
| 1608 | { | ||
| 1609 | var things: struct { | ||
| 1610 | comptime foo: i8 = 1, | ||
| 1611 | } = undefined; // Segmentation fault at address 0x0 | ||
| 1612 | |||
| 1613 | comptime std.debug.assert(things.foo == 1); | ||
| 1614 | } | ||
| 1615 | } |
test/behavior/type_info.zig+6| ... | @@ -603,3 +603,9 @@ test "@typeInfo decls ignore dependency loops" { | ... | @@ -603,3 +603,9 @@ test "@typeInfo decls ignore dependency loops" { |
| 603 | }; | 603 | }; |
| 604 | _ = S.foo; | 604 | _ = S.foo; |
| 605 | } | 605 | } |
| 606 | |||
| 607 | test "type info of tuple of string literal default value" { | ||
| 608 | const struct_field = @typeInfo(@TypeOf(.{"hi"})).Struct.fields[0]; | ||
| 609 | const value = @ptrCast(*align(1) const *const [2:0]u8, struct_field.default_value.?).*; | ||
| 610 | comptime std.debug.assert(value[0] == 'h'); | ||
| 611 | } |
test/cases/compile_errors/error_set_membership.zig created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | |||
| 3 | const Error = error{InvalidCharacter}; | ||
| 4 | |||
| 5 | const Direction = enum { upside_down }; | ||
| 6 | |||
| 7 | const Barrrr = union(enum) { | ||
| 8 | float: f64, | ||
| 9 | direction: Direction, | ||
| 10 | }; | ||
| 11 | |||
| 12 | fn fooey(bar: std.meta.Tag(Barrrr), args: []const []const u8) !Barrrr { | ||
| 13 | return switch (bar) { | ||
| 14 | .float => .{ .float = try std.fmt.parseFloat(f64, args[0]) }, | ||
| 15 | .direction => if (std.mem.eql(u8, args[0], "upside_down")) | ||
| 16 | Barrrr{ .direction = .upside_down } | ||
| 17 | else | ||
| 18 | error.InvalidDirection, | ||
| 19 | }; | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn main() Error!void { | ||
| 23 | std.debug.print("{}", .{try fooey(.direction, &[_][]const u8{ "one", "two", "three" })}); | ||
| 24 | } | ||
| 25 | |||
| 26 | // error | ||
| 27 | // backend=llvm | ||
| 28 | // target=native | ||
| 29 | // | ||
| 30 | // :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).Fn.return_type.?).ErrorUnion.error_set' | ||
| 31 | // :23:29: note: 'error.InvalidDirection' not a member of destination error set | ||