workaround for forcing a subclass to its true type using super class `object` that contains `__class__` the name of the class, and in a generic function switch on the name instead of `G.(type)` because that can be wrong because methods in a base class that return self cast any subclass it returns to the type of the class instance the method is called from.
added debug printing to catch nil pointer in unsafe switch using __class__ name.