aboutsummaryrefslogtreecommitdiff
path: root/test/cases/compile_errors/dereference_anyopaque.zig
blob: c4e4649892360e0c03b5c8e596d56fc78253456c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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.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.failing_allocator;
    _ = parse(std.StringArrayHashMap(bool), allocator) catch return;
}

// error
// target=native
// backend=llvm
//
// :11:22: error: comparison of 'void' with null
// :25:51: error: cannot load opaque type 'anyopaque'
// :25:51: error: values of type 'fn (*anyopaque, usize, u8, usize) ?[*]u8' must be comptime-known, but operand value is runtime-known
// :25:51: note: use '*const fn (*anyopaque, usize, u8, usize) ?[*]u8' for a function pointer type
// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize, usize) bool' must be comptime-known, but operand value is runtime-known
// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize, usize) bool' for a function pointer type
// :25:51: error: values of type 'fn (*anyopaque, []u8, u8, usize) void' must be comptime-known, but operand value is runtime-known
// :25:51: note: use '*const fn (*anyopaque, []u8, u8, usize) void' for a function pointer type