An overloaded toString() method may have side effects so don't call it for a simple type check. Back-port of 54b409d6 to the v0.4 branch.