aboutsummaryrefslogtreecommitdiff
path: root/test/stage1
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-02-11 23:45:40 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-02-11 23:45:40 -0700
commitb4e344bcf859f2df89637e0825a2e0e57d092ef6 (patch)
tree44465c5c3eadcfdc57f0a0a3eb5cffff9107bd7f /test/stage1
parent3d0f4b90305bc1815ccc86613cb3da715e9b62c0 (diff)
parentd3565ed6b48c9c66128f181e7b90b5348504cb3f (diff)
downloadzig-b4e344bcf859f2df89637e0825a2e0e57d092ef6.tar.gz
zig-b4e344bcf859f2df89637e0825a2e0e57d092ef6.zip
Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts: * lib/std/zig/ast.zig * lib/std/zig/parse.zig * lib/std/zig/parser_test.zig * lib/std/zig/render.zig * src/Module.zig * src/zir.zig I resolved some of the conflicts by reverting a small portion of @tadeokondrak's stage2 logic here regarding `callconv(.Inline)`. It will need to get reworked as part of this branch.
Diffstat (limited to 'test/stage1')
-rw-r--r--test/stage1/behavior/bugs/1322.zig4
-rw-r--r--test/stage1/behavior/enum.zig15
-rw-r--r--test/stage1/behavior/fn.zig2
-rw-r--r--test/stage1/behavior/type_info.zig2
-rw-r--r--test/stage1/behavior/union.zig45
5 files changed, 35 insertions, 33 deletions
diff --git a/test/stage1/behavior/bugs/1322.zig b/test/stage1/behavior/bugs/1322.zig
index 3231a985e7..02ead6afff 100644
--- a/test/stage1/behavior/bugs/1322.zig
+++ b/test/stage1/behavior/bugs/1322.zig
@@ -13,7 +13,7 @@ const C = struct {};
test "tagged union with all void fields but a meaningful tag" {
var a: A = A{ .b = B{ .c = C{} } };
- std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).c);
+ std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).c);
a = A{ .b = B.None };
- std.testing.expect(@as(@TagType(B), a.b) == @TagType(B).None);
+ std.testing.expect(@as(std.meta.Tag(B), a.b) == std.meta.Tag(B).None);
}
diff --git a/test/stage1/behavior/enum.zig b/test/stage1/behavior/enum.zig
index 1d424d6e39..ecb95be8f5 100644
--- a/test/stage1/behavior/enum.zig
+++ b/test/stage1/behavior/enum.zig
@@ -1,5 +1,6 @@
const expect = @import("std").testing.expect;
const mem = @import("std").mem;
+const Tag = @import("std").meta.Tag;
test "extern enum" {
const S = struct {
@@ -827,12 +828,12 @@ test "set enum tag type" {
{
var x = Small.One;
x = Small.Two;
- comptime expect(@TagType(Small) == u2);
+ comptime expect(Tag(Small) == u2);
}
{
var x = Small2.One;
x = Small2.Two;
- comptime expect(@TagType(Small2) == u2);
+ comptime expect(Tag(Small2) == u2);
}
}
@@ -905,11 +906,11 @@ fn getC(data: *const BitFieldOfEnums) C {
}
test "casting enum to its tag type" {
- testCastEnumToTagType(Small2.Two);
- comptime testCastEnumToTagType(Small2.Two);
+ testCastEnumTag(Small2.Two);
+ comptime testCastEnumTag(Small2.Two);
}
-fn testCastEnumToTagType(value: Small2) void {
+fn testCastEnumTag(value: Small2) void {
expect(@enumToInt(value) == 1);
}
@@ -1163,14 +1164,14 @@ test "enum with comptime_int tag type" {
Two = 2,
Three = 1,
};
- comptime expect(@TagType(Enum) == comptime_int);
+ comptime expect(Tag(Enum) == comptime_int);
}
test "enum with one member default to u0 tag type" {
const E0 = enum {
X,
};
- comptime expect(@TagType(E0) == u0);
+ comptime expect(Tag(E0) == u0);
}
test "tagName on enum literals" {
diff --git a/test/stage1/behavior/fn.zig b/test/stage1/behavior/fn.zig
index dd69d00c60..a1e726c565 100644
--- a/test/stage1/behavior/fn.zig
+++ b/test/stage1/behavior/fn.zig
@@ -113,7 +113,7 @@ test "assign inline fn to const variable" {
a();
}
-inline fn inlineFn() void {}
+fn inlineFn() callconv(.Inline) void {}
test "pass by non-copying value" {
expect(addPointCoords(Point{ .x = 1, .y = 2 }) == 3);
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index aa5ac89c94..6dec7ca4d2 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -14,7 +14,7 @@ test "type info: tag type, void info" {
}
fn testBasic() void {
- expect(@TagType(TypeInfo) == TypeId);
+ expect(@typeInfo(TypeInfo).Union.tag_type == TypeId);
const void_info = @typeInfo(void);
expect(void_info == TypeId.Void);
expect(void_info.Void == {});
diff --git a/test/stage1/behavior/union.zig b/test/stage1/behavior/union.zig
index 63f36e755a..e46b6bb6b9 100644
--- a/test/stage1/behavior/union.zig
+++ b/test/stage1/behavior/union.zig
@@ -1,6 +1,7 @@
const std = @import("std");
const expect = std.testing.expect;
const expectEqual = std.testing.expectEqual;
+const Tag = std.meta.Tag;
const Value = union(enum) {
Int: u64,
@@ -128,7 +129,7 @@ const MultipleChoice = union(enum(u32)) {
test "simple union(enum(u32))" {
var x = MultipleChoice.C;
expect(x == MultipleChoice.C);
- expect(@enumToInt(@as(@TagType(MultipleChoice), x)) == 60);
+ expect(@enumToInt(@as(Tag(MultipleChoice), x)) == 60);
}
const MultipleChoice2 = union(enum(u32)) {
@@ -144,13 +145,13 @@ const MultipleChoice2 = union(enum(u32)) {
};
test "union(enum(u32)) with specified and unspecified tag values" {
- comptime expect(@TagType(@TagType(MultipleChoice2)) == u32);
+ comptime expect(Tag(Tag(MultipleChoice2)) == u32);
testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
comptime testEnumWithSpecifiedAndUnspecifiedTagValues(MultipleChoice2{ .C = 123 });
}
fn testEnumWithSpecifiedAndUnspecifiedTagValues(x: MultipleChoice2) void {
- expect(@enumToInt(@as(@TagType(MultipleChoice2), x)) == 60);
+ expect(@enumToInt(@as(Tag(MultipleChoice2), x)) == 60);
expect(1123 == switch (x) {
MultipleChoice2.A => 1,
MultipleChoice2.B => 2,
@@ -204,11 +205,11 @@ test "union field access gives the enum values" {
}
test "cast union to tag type of union" {
- testCastUnionToTagType(TheUnion{ .B = 1234 });
- comptime testCastUnionToTagType(TheUnion{ .B = 1234 });
+ testCastUnionToTag(TheUnion{ .B = 1234 });
+ comptime testCastUnionToTag(TheUnion{ .B = 1234 });
}
-fn testCastUnionToTagType(x: TheUnion) void {
+fn testCastUnionToTag(x: TheUnion) void {
expect(@as(TheTag, x) == TheTag.B);
}
@@ -298,7 +299,7 @@ const TaggedUnionWithAVoid = union(enum) {
fn testTaggedUnionInit(x: anytype) bool {
const y = TaggedUnionWithAVoid{ .A = x };
- return @as(@TagType(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
+ return @as(Tag(TaggedUnionWithAVoid), y) == TaggedUnionWithAVoid.A;
}
pub const UnionEnumNoPayloads = union(enum) {
@@ -309,8 +310,8 @@ pub const UnionEnumNoPayloads = union(enum) {
test "tagged union with no payloads" {
const a = UnionEnumNoPayloads{ .B = {} };
switch (a) {
- @TagType(UnionEnumNoPayloads).A => @panic("wrong"),
- @TagType(UnionEnumNoPayloads).B => {},
+ Tag(UnionEnumNoPayloads).A => @panic("wrong"),
+ Tag(UnionEnumNoPayloads).B => {},
}
}
@@ -325,9 +326,9 @@ test "union with only 1 field casted to its enum type" {
};
var e = Expr{ .Literal = Literal{ .Bool = true } };
- const Tag = @TagType(Expr);
- comptime expect(@TagType(Tag) == u0);
- var t = @as(Tag, e);
+ const ExprTag = Tag(Expr);
+ comptime expect(Tag(ExprTag) == u0);
+ var t = @as(ExprTag, e);
expect(t == Expr.Literal);
}
@@ -337,17 +338,17 @@ test "union with only 1 field casted to its enum type which has enum value speci
Bool: bool,
};
- const Tag = enum(comptime_int) {
+ const ExprTag = enum(comptime_int) {
Literal = 33,
};
- const Expr = union(Tag) {
+ const Expr = union(ExprTag) {
Literal: Literal,
};
var e = Expr{ .Literal = Literal{ .Bool = true } };
- comptime expect(@TagType(Tag) == comptime_int);
- var t = @as(Tag, e);
+ comptime expect(Tag(ExprTag) == comptime_int);
+ var t = @as(ExprTag, e);
expect(t == Expr.Literal);
expect(@enumToInt(t) == 33);
comptime expect(@enumToInt(t) == 33);
@@ -501,7 +502,7 @@ test "union with one member defaults to u0 tag type" {
const U0 = union(enum) {
X: u32,
};
- comptime expect(@TagType(@TagType(U0)) == u0);
+ comptime expect(Tag(Tag(U0)) == u0);
}
test "union with comptime_int tag" {
@@ -510,7 +511,7 @@ test "union with comptime_int tag" {
Y: u16,
Z: u8,
};
- comptime expect(@TagType(@TagType(Union)) == comptime_int);
+ comptime expect(Tag(Tag(Union)) == comptime_int);
}
test "extern union doesn't trigger field check at comptime" {
@@ -591,7 +592,7 @@ test "function call result coerces from tagged union to the tag" {
Two: usize,
};
- const ArchTag = @TagType(Arch);
+ const ArchTag = Tag(Arch);
fn doTheTest() void {
var x: ArchTag = getArch1();
@@ -696,8 +697,8 @@ test "cast from pointer to anonymous struct to pointer to union" {
test "method call on an empty union" {
const S = struct {
- const MyUnion = union(Tag) {
- pub const Tag = enum { X1, X2 };
+ const MyUnion = union(MyUnionTag) {
+ pub const MyUnionTag = enum { X1, X2 };
X1: [0]u8,
X2: [0]u8,
@@ -797,7 +798,7 @@ test "union enum type gets a separate scope" {
};
fn doTheTest() void {
- expect(!@hasDecl(@TagType(U), "foo"));
+ expect(!@hasDecl(Tag(U), "foo"));
}
};