Skip to content

Commit 8ffa2d7

Browse files
committed
behavior: add more test coverage for old stage1 issues
Closes #12169 Closes #12450 Closes #13113 Closes #12057 Closes #12051 Closes #12092 Closes #12116 Closes #12119 Closes #12142 Closes #12450 Closes #13113 Closes #11986 Closes #11995 Closes #12000
1 parent 88b49ed commit 8ffa2d7

14 files changed

+186
-0
lines changed

test/behavior.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,21 @@ test {
9191
_ = @import("behavior/bugs/11213.zig");
9292
_ = @import("behavior/bugs/11787.zig");
9393
_ = @import("behavior/bugs/11816.zig");
94+
_ = @import("behavior/bugs/11986.zig");
95+
_ = @import("behavior/bugs/11995.zig");
96+
_ = @import("behavior/bugs/12000.zig");
9497
_ = @import("behavior/bugs/12003.zig");
9598
_ = @import("behavior/bugs/12025.zig");
9699
_ = @import("behavior/bugs/12033.zig");
97100
_ = @import("behavior/bugs/12043.zig");
101+
_ = @import("behavior/bugs/12051.zig");
102+
_ = @import("behavior/bugs/12092.zig");
103+
_ = @import("behavior/bugs/12119.zig");
104+
_ = @import("behavior/bugs/12116.zig");
105+
_ = @import("behavior/bugs/12142.zig");
106+
_ = @import("behavior/bugs/12169.zig");
98107
_ = @import("behavior/bugs/12430.zig");
108+
_ = @import("behavior/bugs/12450.zig");
99109
_ = @import("behavior/bugs/12486.zig");
100110
_ = @import("behavior/bugs/12488.zig");
101111
_ = @import("behavior/bugs/12498.zig");
@@ -121,6 +131,7 @@ test {
121131
_ = @import("behavior/bugs/13068.zig");
122132
_ = @import("behavior/bugs/13069.zig");
123133
_ = @import("behavior/bugs/13112.zig");
134+
_ = @import("behavior/bugs/13113.zig");
124135
_ = @import("behavior/bugs/13128.zig");
125136
_ = @import("behavior/bugs/13159.zig");
126137
_ = @import("behavior/bugs/13164.zig");

test/behavior/bugs/11986.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
test {
2+
const lang: []const u8 = "lang";
3+
const targets: [1][]const u8 = [_][]u8{lang};
4+
_ = targets;
5+
}

test/behavior/bugs/11995.zig

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
fn wuffs_base__make_io_buffer(arg_data: wuffs_base__slice_u8, arg_meta: wuffs_base__io_buffer_meta) callconv(.C) void {
2+
_ = arg_data;
3+
_ = arg_meta;
4+
}
5+
const wuffs_base__io_buffer_meta = extern struct {
6+
wi: usize,
7+
ri: usize,
8+
pos: u64,
9+
closed: bool,
10+
};
11+
const wuffs_base__slice_u8 = extern struct {
12+
ptr: [*c]u8,
13+
len: usize,
14+
};
15+
test {
16+
_ = wuffs_base__make_io_buffer(undefined, undefined);
17+
}

test/behavior/bugs/12000.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const T = struct {
2+
next: @TypeOf(null, @as(*const T, undefined)),
3+
};
4+
5+
test {
6+
_ = T;
7+
}

test/behavior/bugs/12051.zig

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
test {
2+
const x = X{};
3+
_ = x;
4+
}
5+
6+
const X = struct {
7+
y: Y = Y.init(),
8+
};
9+
10+
const Y = struct {
11+
a: u16,
12+
b: bool,
13+
c: Z,
14+
d: Z,
15+
16+
fn init() Y {
17+
return .{
18+
.a = 0,
19+
.b = false,
20+
.c = @bitCast(Z, @as(u32, 0)),
21+
.d = @bitCast(Z, @as(u32, 0)),
22+
};
23+
}
24+
};
25+
26+
const Z = packed struct {
27+
a: u32,
28+
};

test/behavior/bugs/12092.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const Foo = struct {
2+
a: Bar,
3+
};
4+
5+
const Bar = struct {
6+
b: u32,
7+
};
8+
9+
fn takeFoo(foo: *const Foo) void {
10+
_ = foo;
11+
}
12+
13+
test {
14+
var baz: u32 = 24;
15+
takeFoo(&.{
16+
.a = .{
17+
.b = baz,
18+
},
19+
});
20+
}

test/behavior/bugs/12116.zig

Lines changed: 4 additions & 0 deletions
Large diffs are not rendered by default.

test/behavior/bugs/12119.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const u8x32 = @Vector(32, u8);
2+
const u32x8 = @Vector(8, u32);
3+
4+
test {
5+
const zerox32: u8x32 = [_]u8{0} ** 32;
6+
const bigsum: u32x8 = @bitCast(u32x8, zerox32);
7+
_ = bigsum;
8+
}

test/behavior/bugs/12142.zig

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const std = @import("std");
2+
3+
const Holder = struct {
4+
array: []const u8,
5+
};
6+
7+
const Test = struct {
8+
holders: []const Holder,
9+
};
10+
11+
const Letter = enum(u8) {
12+
A = 0x41,
13+
B,
14+
};
15+
16+
fn letter(e: Letter) u8 {
17+
return @enumToInt(e);
18+
}
19+
20+
test {
21+
const test_struct = Test{
22+
.holders = &.{
23+
Holder{
24+
.array = &.{
25+
letter(.A),
26+
},
27+
},
28+
},
29+
};
30+
try std.testing.expectEqualStrings("A", test_struct.holders[0].array);
31+
}

test/behavior/bugs/12169.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
test {
2+
_ = @Vector(2, bool){ true, true };
3+
_ = @Vector(1, bool){true};
4+
}

test/behavior/bugs/12450.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const expect = @import("std").testing.expect;
2+
3+
const Foo = packed struct {
4+
a: i32,
5+
b: u8,
6+
};
7+
8+
var buffer: [256]u8 = undefined;
9+
10+
test {
11+
var f1: *align(16) Foo = @alignCast(16, @ptrCast(*align(1) Foo, &buffer[0]));
12+
try expect(@typeInfo(@TypeOf(f1)).Pointer.alignment == 16);
13+
try expect(@ptrToInt(f1) == @ptrToInt(&f1.a));
14+
try expect(@typeInfo(@TypeOf(&f1.a)).Pointer.alignment == 16);
15+
}

test/behavior/bugs/13113.zig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const Foo = extern struct {
2+
a: u8 align(1),
3+
b: u16 align(1),
4+
};
5+
6+
test {
7+
const foo = Foo{
8+
.a = 1,
9+
.b = 2,
10+
};
11+
_ = foo;
12+
}

test/cases/compile_errors/implicit_cast_const_array_to_mutable_slice.zig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export fn entry2() void {
1313
const many: [*]u8 = str;
1414
_ = many;
1515
}
16+
export fn entry3() void {
17+
const lang: []const u8 = "lang";
18+
const targets: [1][]const u8 = [_][]u8{lang};
19+
_ = targets;
20+
}
1621

1722
// error
1823
// backend=stage2
@@ -24,3 +29,5 @@ export fn entry2() void {
2429
// :8:27: note: cast discards const qualifier
2530
// :13:25: error: expected type '[*]u8', found '*const [0:0]u8'
2631
// :13:25: note: cast discards const qualifier
32+
// :18:44: error: expected type '[]u8', found '[]const u8'
33+
// :18:44: note: cast discards const qualifier
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const std = @import("std");
2+
3+
test "comptime expression" {
4+
comptime {
5+
std.log.warn("hello in comptime", .{});
6+
}
7+
}
8+
9+
// error
10+
// backend=stage2
11+
// target=native
12+
//
13+
// :110:38: error: unable to evaluate comptime expression
14+
// :110:60: note: operation is runtime due to this operand
15+
// :139:21: note: called from here
16+
// :190:16: note: called from here
17+
// :5:21: note: called from here

0 commit comments

Comments
 (0)