1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-18 03:29:32 +00:00

Assert that the loop variable is meaningful in repeat. Unit test.

This commit is contained in:
Chris Pressey 2017-11-20 16:39:39 +00:00
parent 0e9a887ac5
commit c33e6ef0e9
2 changed files with 21 additions and 3 deletions

View File

@ -286,12 +286,13 @@ class Analyzer(object):
# it will always be executed at least once, so analyze it having
# been executed the first time.
self.analyze_block(instr.block, context)
context.assert_meaningful(src)
# now analyze it having been executed a second time, with the context
# of it having already been executed.
self.analyze_block(instr.block, context)
# NB I *think* that's enough... but it might not be?
context.assert_meaningful(src)
elif opcode == 'copy':
# check that their types are basically compatible
if src.type == dest.type:

View File

@ -1017,6 +1017,23 @@ initialized at the start.
| }
? UnmeaningfulReadError: y in main
And if you trash the test expression (i.e. `z` in the below) inside the loop,
this is an error too.
| word one : 0
| word two : 0
|
| routine main
| inputs one, two
| outputs two
| trashes a, z, n
| {
| repeat {
| copy one, two
| } until z
| }
? UnmeaningfulReadError: z in main
### copy ###
Can't `copy` from a memory location that isn't initialized.