CQM-GeneralParameter

Parameters of a function shall not get casted to a more specific type

Required inputs: IR

Any parameter of a routine that gets casted to a more specific type is a violation. Routines declared in a superclass are not considered.

Motivation

A general data type is specified as the type for a routine parameter. Within the routine, however, a more specific data type of the parameter is assumed. Via a typecast, the type of the parameter is converted into this data type and used. The specification of the general data type therefore suggests to a client a generality that does not exist at all and thus cannot be used by the client as expected. This is particularly dangerous because type errors, which can occur when using the assumed generality, only occur at runtime.

This rule is based on the CQM Quality Indicator: allgemeine Parameter (p. 167-170).

Reference

Simon, Frank/ Seng, Olaf/ Mohaupt, Thomas (2006): Code-Quality-Management: Technische Qualität industrieller Softwaresysteme transparent und vergleichbar gemacht, 1st ed., Heidelberg, Germany: dpunkt.verlag GmbH.

Possible Messages

Key

Text

Severity

Disabled

parameter_cast

This parameter gets casted to a more specific type.

None

False

Options

cast_types

cast_types

Type: set[CastOptions]

Default: {'Const_Cast', 'Dynamic_Cast', 'Reinterpret_Cast', 'Static_Cast'}

Set with the cast types, which if used constitute a violation.
 

Option Types

These types are used by options listed above:

CastOptions

An enumeration.
 
  • C_Cast

  • Function_Notation_Cast

  • Braced_Notation_Cast

  • Reinterpret_Cast

  • Static_Cast

  • Const_Cast

  • Dynamic_Cast

  • Managed_Safe_Cast