Fix bug in leaveBlock().

When leaving the last block, we must reset the block counter. Other-
wise we can never reach the blocks again later during type-checking :)

Also update the unit test to do the entire sequence of enterBlock() /
leaveBlock() calls again and make sure it works as expected.