435
src/Sema.zig
435
src/Sema.zig
File diff suppressed because it is too large
Load Diff
@@ -2645,6 +2645,7 @@ pub const Value = extern union {
|
||||
}
|
||||
unreachable;
|
||||
},
|
||||
.undef => return Value.undef,
|
||||
|
||||
else => unreachable,
|
||||
}
|
||||
|
||||
@@ -280,3 +280,23 @@ test "@sizeOf comparison against zero" {
|
||||
try S.doTheTest(S1, true);
|
||||
try S.doTheTest(U1, true);
|
||||
}
|
||||
|
||||
test "hardcoded address in typeof expression" {
|
||||
const S = struct {
|
||||
fn func() @TypeOf(@intToPtr(*[]u8, 0x10).*[0]) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
try expect(S.func() == 0);
|
||||
comptime try expect(S.func() == 0);
|
||||
}
|
||||
|
||||
test "array access of generic param in typeof expression" {
|
||||
const S = struct {
|
||||
fn first(comptime items: anytype) @TypeOf(items[0]) {
|
||||
return items[0];
|
||||
}
|
||||
};
|
||||
try expect(S.first("a") == 'a');
|
||||
comptime try expect(S.first("a") == 'a');
|
||||
}
|
||||
|
||||
@@ -1319,3 +1319,24 @@ test "packed struct aggregate init" {
|
||||
const result = @bitCast(u8, S.foo(1, 2));
|
||||
try expect(result == 9);
|
||||
}
|
||||
|
||||
test "packed struct field access via pointer" {
|
||||
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
|
||||
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
|
||||
|
||||
const S = struct {
|
||||
fn doTheTest() !void {
|
||||
const S = packed struct { a: u30 };
|
||||
var s1: S = .{ .a = 1 };
|
||||
var s2 = &s1;
|
||||
try expect(s2.a == 1);
|
||||
var s3: S = undefined;
|
||||
var s4 = &s3;
|
||||
_ = s4;
|
||||
}
|
||||
};
|
||||
try S.doTheTest();
|
||||
comptime try S.doTheTest();
|
||||
}
|
||||
|
||||
50
test/cases/compile_errors/dereference_anyopaque.zig
Normal file
50
test/cases/compile_errors/dereference_anyopaque.zig
Normal file
@@ -0,0 +1,50 @@
|
||||
const std = @import("std");
|
||||
|
||||
const Error = error{Something};
|
||||
|
||||
fn next() Error!void {
|
||||
return;
|
||||
}
|
||||
|
||||
fn parse(comptime T: type, allocator: std.mem.Allocator) !void {
|
||||
parseFree(T, undefined, allocator);
|
||||
_ = (try next()) != null;
|
||||
}
|
||||
|
||||
fn parseFree(comptime T: type, value: T, allocator: std.mem.Allocator) void {
|
||||
switch (@typeInfo(T)) {
|
||||
.Struct => |structInfo| {
|
||||
inline for (structInfo.fields) |field| {
|
||||
if (!field.is_comptime)
|
||||
parseFree(field.field_type, undefined, allocator);
|
||||
}
|
||||
},
|
||||
.Pointer => |ptrInfo| {
|
||||
switch (ptrInfo.size) {
|
||||
.One => {
|
||||
parseFree(ptrInfo.child, value.*, allocator);
|
||||
},
|
||||
.Slice => {
|
||||
for (value) |v|
|
||||
parseFree(ptrInfo.child, v, allocator);
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
},
|
||||
else => unreachable,
|
||||
}
|
||||
}
|
||||
|
||||
pub export fn entry() void {
|
||||
const allocator = std.testing.allocator_instance.allocator();
|
||||
_ = parse(std.StringArrayHashMap(bool), allocator) catch return;
|
||||
}
|
||||
|
||||
// error
|
||||
// backend=llvm
|
||||
//
|
||||
// :11:22: error: comparison of 'void' with null
|
||||
// :25:51: error: unable to resolve comptime value
|
||||
// :25:51: error: unable to resolve comptime value
|
||||
// :25:51: error: unable to resolve comptime value
|
||||
// :25:51: error: unable to resolve comptime value
|
||||
Reference in New Issue
Block a user