#switch return error

1 messages · Page 1 of 1 (latest)

exotic granite
#

im trying to return an integer from a switch case:
run() catch |err| { var sdl_err: i32 = switch (err) { Error.SDL => { logSDLError(); return c.SDL_ShowSimpleMessageBox(c.SDL_MESSAGEBOX_ERROR, error_title, c.SDL_GetError(), error_window); }, Error.IMG => { logIMGError(); return c.SDL_ShowSimpleMessageBox(c.SDL_MESSAGEBOX_ERROR, error_title, c.IMG_GetError(), error_window); }, else => 0, }; if (sdl_err != 0) { logSDLError(); } };

the compiler says ./src/root.zig:125:50: error: expected type 'void', found 'c_int' return c.SDL_ShowSimpleMessageBox(c.SDL_MESSAGEBOX_ERROR, error_title, c.SDL_GetError(), error_window);

late sigil
#

are you sure your function isn't written to have a return type void?

exotic granite
late sigil
#

I mean the function you wrote

#

the function wherein the switch is contained

#

because if it's void, that'd be your issue

exotic granite
#

yes its void but i dont see whats the matter, im trying to assign a value to sdl_err

#

oh i know what i did wrong

late sigil
#

return c.SDL_ShowSimpleMessageBox(...)

#

that return statement is for the function

exotic granite
#

im dumb

late sigil
#

probably what you want is to label the bock like blk: {...}

#

and then do break :blk instead of return

exotic granite
#

ok thanks let me fix this and ill close the issue

#

done