When I try to use this proc, it refuses to compile

@(require_results)
fs_create_dummy::proc(filename:string,my_json: Core.Material_raw_json_t) -> (err:Maybe(any))
{
    context.allocator=context.temp_allocator
    mat_fullpath := strings.concatenate({CWD_PATH, PATH_REL_OF_MATERIALS,".mat"}) or_return
    filehandle := os2.create(mat_fullpath) or_return
    json_bytes := json.marshal(my_json) or_return
    _ = os2.write(filehandle, json_bytes) or_return
    os2.close(filehandle) or_return
    return nil
}
xd

dont take this seriously, I was just exploring the limits of Maybe

1 Like

Returning any is almost always a bad idea. any is effectively a pointer, and you’d be returning a pointer to something that then goes out of scope.

Be very careful about using any unless you’re sure you know how it works.

1 Like

So regardless of it not compiling This is also extremely dangerous. I’ll repeat what I normally say to everyone:

Do not use any unless you know exactly how it works!

And you’ve just used any in a way that that doesn’t work well.

All of those use cases of or_return return a stack pointer, and thus is very dangerous.

mat_fullpath := strings.concatenate({CWD_PATH, PATH_REL_OF_MATERIALS,".mat"}) or_return

Is actually doing the following:

mat_fullpath, ok := strings.concatenate({CWD_PATH, PATH_REL_OF_MATERIALS,".mat"})
if !ok {
    err_any: any
    err_any.data = &ok
    err_any.id = typeid_of(type_of(ok))
    err = err_any
    return
}

Note how it is doing the &ok bit.

5 Likes

Maybe we would be better off calling them “reflective pointers” or something

1 Like