Fix undefined vars tests: issue 3989

Fix the known test failures for the undefined vars test code added in e3adfbf ; Full details of the fixes are in the underlying commit messages for these two revs.

Any questions or issues please let me know prior to a close (I'll update it as needed, but chasing PRs loses info).