Fix #3693 (variable ref'ed before assignment)

Also, fix another reference before assignment in the "test=True" code
block
Merge pull request #3695 from archtaku/issue3693

Fix #3693 (variable ref'ed before assignment)