Fix for issue #97: ClassCastException with polymorphic middle binding