#Cannot load runtime value in comptime block

1 messages · Page 1 of 1 (latest)

vast gulch
#

Does anyone know what would cause this error message?

/Users/danielbokser/zig/lib/toolbox/memory.zig:286:29: error: cannot load runtime value in comptime block
    const data_opt = toolbox.playdate_realloc(null, n);
~~~~~~~^~~~~~~~~~~~~~~~~

this is the context: https://zigbin.io/27c937

zinc bay
#

To me it looks like you are calling playdate_allocate_memory in a comptime context but I can't tell for sure without the callsite

zinc bay
#

The call site of playdate_allocate_memory, not playdate_realloc
I don't know why the compiler would think that line is happening at comptime otherwise

zinc bay
#

Hmm, that does seem weird

vast gulch
# zinc bay Hmm, that does seem weird

ah sorry: this is where playdate_allocate_memory is used

const platform_allocate_memory = switch (toolbox.THIS_PLATFORM) {
    //.MacOS => unix_allocate_memory,
    //.MacOS => posix_allocate_memory,
    .MacOS => macos_allocate_memory,
    .BoksOS => boksos_allocate_memory,
    .Playdate => playdate_allocate_memory,
};
#

and THIS_PLATFORM is a comptime value

tidal thicket
#

that's fine, that just means the switch gets evaluated at comptime

#

but how do we get from platform_allocate_memory to toolbox.os_allocate_object?

vast gulch
#

so is the issue the T parameter?

tidal thicket
#

no it shouldn't be...

#

btw platform_allocate_memory should probably take alignment as an argument

#

unless it's already guaranteed to have maximum alignment

#

but I have no idea what causes the error tho

#

unless... could you try .Playdate => &playdate_allocate_memory,?

#

but that shouldn't actually matter, nvm

vast gulch
vast gulch
tidal thicket
#

last thing I can think of is if it's something in the definition of toolbox but I doubt it

#

oooor, it could be that GlobalState is a comptime only type

#

that's more likely

vast gulch
vast gulch
tidal thicket
#

that's one option, can I see it?

vast gulch
#

really need better error messages with this comptime function pointer feature lol

tidal thicket
#

in general better errors, but good that you found it 👍