You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When this code returns, unless the function runs first and returns null, it will return State{ .Playing = }. If the function is run and returns null and is then run to return PlayingState.init(...) it will return State{ .Playing = PlayingState{ <data> }}.
With the relevant code cut out:
// in main game loop, game_state is State { .MainMenu = MainMenuState }for (pressed_keys.toSlice()) |key|if (game_state.handleKey(&ctx, key)) |state| {
std.debug.warn("switching to a new state!\n");
game_state=state;
};
pressed_keys.shrink(0);
// in StatefnhandleKey(state: *State, ctx: *Context, key: Key) ?State {
switch (state.*) {
.Playing=>|*s|...,
.MainMenu=>|*s|switch (key) {
.Space=>returnPlayingState.init(c_allocator, ctx),
.Escape=> {
c.glfwSetWindowShouldClose(ctx.window, c.GL_TRUE);
returnnull;
},
else=>returnnull,
},
}
}
A few examples of what happens, $ is terminal output, <> and () are what is going on:
<space is pressed>
$ switching to a new state!
(no state switch happens)
<space is pressed>
$ switching to a new state!
(no state switch happens)
<up is pressed>
<space is pressed>
(state switch happens successfully)
<up is pressed>
<space is pressed>
$ switching to a new state!
(state switches successfully)
I believe that the compiler should not allow the return to just be PlayingState.init(...), because it is not correct. The current way it does it does not work as expected.
The text was updated successfully, but these errors were encountered:
here's a reduction that I think is pretty close to the issue.
when using initDirect() compiler is uncertain about the type of container being initialized
when using initCall() compiler does not error and generates llvm-ir to call a function with result-location type mismatch (llvm-ir appended below); looks related to broken module with error union and union(enum) #2881
reduction.zig: use one of { initDirect() or initCall() }
exportfnfoo() void {
varstate=initDirect();
//var state = initCall();
}
// error: no member named 'value' in union 'StatefninitDirect() State {
returnOne{ .value=255 };
}
// llvm-ir error: Call parameter type does not match function signature!fninitCall() State {
returnOne.init();
}
constState=union(enum) {
one: One,
};
constOne=struct {
value: u8,
fninit() One {
returnOne{ .value=255 };
}
};
llvm-ir when using initCall() -- One.init() is called with %State* result-location
When this code returns, unless the function runs first and returns null, it will return
State{ .Playing = }
. If the function is run and returns null and is then run to returnPlayingState.init(...)
it will returnState{ .Playing = PlayingState{ <data> }}
.With the relevant code cut out:
A few examples of what happens, $ is terminal output, <> and () are what is going on:
I believe that the compiler should not allow the return to just be
PlayingState.init(...)
, because it is not correct. The current way it does it does not work as expected.The text was updated successfully, but these errors were encountered: