Fix #1731
Issue #1731: Add a test and update some .src which have changed.
Issue #1731: Add a test for all the various is optimizations.
Issue #1731: Tidy up the type test transformation code, more clearly separating out the different cases.