#Use of undefined value but not undefined

1 messages · Page 1 of 1 (latest)

digital vault
#

I'm currently working on code gen for GDExtension. I have this function

pub var variant_from_string: interface.VariantFromTypeConstructorFunc = null;

const std = @import("std");
pub fn init(p_get_proc_address: interface.InterfaceGetProcAddress) !void {
    fns.init(p_get_proc_address);
    init_type_api(fns);
    init_singletons(fns);
    init_util_func(fns);
    variant_from_string = fns.get_variant_from_type_constructor.?(interface.VariantTypes.STRING);
    var string: types.String = undefined;
    var variant: types.Variant = .{ .no_touch = std.mem.zeroes([24]u8) };
    fns.string_new_with_utf8_chars.?(&string, "ZIG IS FULLY INITILIZED!!!\n");
    variant_from_string.?(
        &variant,
        &string,
    );
    @setRuntimeSafety(false);
    util_fns.general.@"print 2648703342"(variant);
    @setRuntimeSafety(true);
}

with the error

gdextension/api.zig:28:41: error: use of undefined value here causes undefined behavior
    util_fns.general.@"print 2648703342"(variant);
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
referenced by:
    initalize: src/extension.zig:14:12
    hello_extension_entry: src/extension.zig:31:25
    remaining reference traces hidden; use '-freference-trace' to see all reference traces
error: the following command failed with 1 compilation errors:

I don't understand why the compiler believes the variant is undefined.
I was hoping I could just disable the check(setRuntimeSafety), but

  1. It didn't work
  2. I should probably fix the underlying issue
honest harness
#

what type is fns?

digital vault
#

hopefully an initlized version of

get_godot_version: interface.InterfaceGetGodotVersion = undefined, // p_get_proc_address("get_godot_version"),
mem_alloc: interface.InterfaceMemAlloc = undefined, // p_get_proc_address("mem_alloc"),
mem_realloc: interface.InterfaceMemRealloc = undefined, // p_get_proc_address("mem_realloc"),
mem_free: interface.InterfaceMemFree = undefined, // p_get_proc_address("mem_free"),
print_error: interface.InterfacePrintError = undefined, // p_get_proc_address("print_error"),
print_error_with_message: interface.InterfacePrintErrorWithMessage = undefined, // 
...
plush swift
#

passing undefined is not ub, maybe you are calling undefined?

digital vault
#
```
pub fn init(self: *@This(), p_get_proc_address: interface.InterfaceGetProcAddress) void {
    const t: std.builtin.Type = @typeInfo(@This());
    inline for (t.Struct.fields) |field| {
        @field(self, field.name) = @as(field.type, @ptrCast(p_get_proc_address.?(field.name)));
    }
}
```~~~
No wait
honest harness
plush swift
#

you can check with @compileLog(util_fns.general.@"print 2648703342");

digital vault
#

unfortunatly it's initlized at runtime

#

init_type_api doesn't init the fns. it uses the functions to init

plush swift
digital vault
#

I did I make it const? oops

#

Lol damn. that'll do it

#

Shouldn't have complained that I assigned to a const?

plush swift
#

where do you think you assigned to it?

digital vault
#

init_util_func

plush swift
#

That iterates over fields, const and var create global constant and global variable decls

#

Since there are no fields, the inline for never loops, so the loop body is never analyzed by the compiler.