Issue #1116: Factor out hasDependentTypeParameters()
Issue #1116: Use hasDependentTypeParameters() when deciding whether a typecast is needed. Note that if the type arguments are exactly the same a typecast isn't necessarily required.
Issue #1116: Update tests