Add type checking to list argument in foreach. Create a test to check
that the error is caught.

Change-Id: Id032cd6fb1e27040b86337c71180eab098beb00b