Re-fix #1226 by adding a check that the type we're testing for is a subtype of Object

Otherwise we may be actually trying to check that something _is_ null, as opposed to what we're
trying to optimise.
Fixed some minor issues mentioned by @fromage (#1203)