foreach range uses same logic as ?: for type deduction

This pull request partly addresses the issue raised by bug 1878. When both types in the range expression are the same, that type will be used for the iteration variable. This is similar to the way ?: deduces types.

Both ?: and range expression should use VRP logic, eventually.