#Weird compile error

1 messages · Page 1 of 1 (latest)

fading bison
#

Can anyone give me a hand with this compile error please? Thanks

    pub fn getType(value: *Value, unit: *Unit) Type.Index {
        return switch (value.*) {
            .type => Type.Index.type,
            .bool => Type.Index.comptime_bool,
            .copy => |value_index| b: {
                const v = unit.values.get(value_index);
                @compileLog(@TypeOf(v), @TypeOf(value));
                break :b v.getType(unit);
            },
            // .file => Type.Index.type,
            else => |t| @panic(@tagName(t)),
        };
    }
bootstrap/Compilation.zig:4851:27: error: no field or member function named 'getType' in 'Compilation.Value'
                break :b v.getType(unit);
                         ~^~~~~~~~
bootstrap/Compilation.zig:4810:15: note: union declared here
const Value = union(enum) {
              ^~~~~
referenced by:
    referenceDeclaration: bootstrap/Compilation.zig:6124:66
    resolveFieldAccess: bootstrap/Compilation.zig:5247:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces

Compile Log Output:
@as(type, *Compilation.Value), @as(type, *Compilation.Value)```
#

more complete:

    unresolved: Node.Index,
    copy: Value.Index,
    type: Type.Index,
    declaration: Declaration.Index,
    bool: bool,

    pub const List = BlockList(@This(), Common);
    pub usingnamespace List.Index;

    const Common = enum{
        bool_false,
        bool_true,

        const map = std.EnumArray(@This(), Value).init(.{
            .bool_false = .{
                .bool = false,
            },
            .bool_true = .{
                .bool = true,
            },
        });
    };

    pub fn isComptime(value: *const Value) bool {
        const result: bool = switch (value.*) {
            .type => true,
            .bool => true,
            else => |t| @panic(@tagName(t)),
        };

        return result;
    }

    pub fn getType(value: *Value, unit: *Unit) Type.Index {
        return switch (value.*) {
            .type => Type.Index.type,
            .bool => Type.Index.comptime_bool,
            .copy => |value_index| b: {
                const v = unit.values.get(value_index);
                comptime {
                    assert(@hasDecl(Value, "getType"));
                    @compileLog(@TypeOf(v), @TypeOf(value));
                }
                break :b Value.getType(v, unit);
            },
            // .file => Type.Index.type,
            else => |t| @panic(@tagName(t)),
        };
    }
};
#
/home/david/dev/zig/lib/std/debug.zig:403:14: error: reached unreachable code
    if (!ok) unreachable; // assertion failure
             ^~~~~~~~~~~
bootstrap/Compilation.zig:4851:27: note: called from here
                    assert(@hasDecl(Value, "getType"));
                    ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    referenceDeclaration: bootstrap/Compilation.zig:6127:66
    resolveFieldAccess: bootstrap/Compilation.zig:5250:32
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
sacred harness
#

dont really get why youd get that assertion failure. but have you tried doing break :b getType(&v, unit);? youll also have to make v var

#

just ran your code and im not getting that assertion failure. maybe youre checking the wrong type in your actual code?