diff --git a/eg/proto-game.60p b/eg/proto-game.60p index 18ff33c..c1d73d5 100644 --- a/eg/proto-game.60p +++ b/eg/proto-game.60p @@ -202,9 +202,6 @@ routine game_state_title_screen // call clear_screen // call init_game copy game_state_play, dispatch_game_state - } else { - // This is sort of a hack. FIXME: let `if` branches diverge this much. - copy forward game_state_title_screen, dispatch_game_state } goto save_cinv diff --git a/tests/SixtyPical Analysis.md b/tests/SixtyPical Analysis.md index 2673c91..42e9f6b 100644 --- a/tests/SixtyPical Analysis.md +++ b/tests/SixtyPical Analysis.md @@ -1065,6 +1065,26 @@ If a location is initialized in one block, is must be initialized in the other a | } ? InconsistentInitializationError: x +However, this only pertains to initialization. If a value is already +initialized, either because it was set previous to the `if`, or is an +input to the routine, and it is initialized in one branch, it need not +be initialized in the other. + + | routine foo + | inputs x + | outputs x + | trashes a, z, n, c + | { + | ld a, 0 + | cmp a, 42 + | if z { + | ld x, 7 + | } else { + | ld a, 23 + | } + | } + = ok + An `if` with a single block is analyzed as if it had an empty `else` block. | routine foo