aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-06-24 15:36:59 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-06-24 15:36:59 -0400
commite42b7702eb2c74b923aa88492886c3f316188e99 (patch)
tree7e4d18651c354ffb7f846316a9661059d963483d /test
parent14aa08fcd3ca6ef32fff9422969cb684cb81b9d7 (diff)
parent129a4fb251f8eab22eacf219fbf81006baec3251 (diff)
downloadzig-e42b7702eb2c74b923aa88492886c3f316188e99.tar.gz
zig-e42b7702eb2c74b923aa88492886c3f316188e99.zip
Merge remote-tracking branch 'origin/master' into zig-ast-to-zir
Diffstat (limited to 'test')
-rw-r--r--test/compile_errors.zig34
-rw-r--r--test/stage1/behavior/type_info.zig8
2 files changed, 42 insertions, 0 deletions
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index e3dd1f0d8f..e8b7e610ee 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -4362,6 +4362,40 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:5:14: note: previous value is here",
});
+ cases.add("switch expression - duplicate type",
+ \\fn foo(comptime T: type, x: T) u8 {
+ \\ return switch (T) {
+ \\ u32 => 0,
+ \\ u64 => 1,
+ \\ u32 => 2,
+ \\ else => 3,
+ \\ };
+ \\}
+ \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
+ , &[_][]const u8{
+ "tmp.zig:5:9: error: duplicate switch value",
+ "tmp.zig:3:9: note: previous value is here",
+ });
+
+ cases.add("switch expression - duplicate type (struct alias)",
+ \\const Test = struct {
+ \\ bar: i32,
+ \\};
+ \\const Test2 = Test;
+ \\fn foo(comptime T: type, x: T) u8 {
+ \\ return switch (T) {
+ \\ Test => 0,
+ \\ u64 => 1,
+ \\ Test2 => 2,
+ \\ else => 3,
+ \\ };
+ \\}
+ \\export fn entry() usize { return @sizeOf(@TypeOf(foo(u32, 0))); }
+ , &[_][]const u8{
+ "tmp.zig:9:9: error: duplicate switch value",
+ "tmp.zig:7:9: note: previous value is here",
+ });
+
cases.add("switch expression - switch on pointer type with no else",
\\fn foo(x: *u8) void {
\\ switch (x) {
diff --git a/test/stage1/behavior/type_info.zig b/test/stage1/behavior/type_info.zig
index 41301f290d..68ff3aa310 100644
--- a/test/stage1/behavior/type_info.zig
+++ b/test/stage1/behavior/type_info.zig
@@ -402,3 +402,11 @@ test "type info for async frames" {
else => unreachable,
}
}
+
+test "type info: value is correctly copied" {
+ comptime {
+ var ptrInfo = @typeInfo([]u32);
+ ptrInfo.Pointer.size = .One;
+ expect(@typeInfo([]u32).Pointer.size == .Slice);
+ }
+}