checkNameIsShadowing

Checks for all variables and functions in the file(s) whether they shadow any existing functionality. For example: if a variable named pi is defined, you will no longer have access to the actual value of π within that scope. This can cause unexpected and undesired behaviour. The MATLAB documentation desribes the precedence order in detail, the goal of this check is to prevent any conflicts with the documented order of precedence.

Variables and functions are reported if they have the same name as one or more of the following:

  • MATLAB-installed functions.

  • Classes

  • Packages

  • MATLAB executable files (MEX): .mexw32, .mexw64, .mexa64, .mexmaci64

  • Simulink files: .mdl, .slx. Detecting the shadowing of a Simulink file requires a Simulink license.

  • Other MATLAB files: .m, .mlx, .mlapp, .p

Hard exceptions

When implementing classes, there are use cases where overloading the functionality of superclasses is required. The functions listed below are ignored by this check when their implementation corresponds with the signature defined in the superclass, regardless of whether they are configured as exceptions.

  • As described in Methods That Modify Default Behavior, certain method names are supposed to overload MATLAB-installed functions.
    • cat, horzcat, vertcat,
    • empty (Static),
    • disp, display,
    • double, char,
    • loadobj (Static), saveobj,
    • permute, reshape, repmat,
    • ctranspose, transpose,
    • isscalar, isvector, ismatrix, isempty,
  • MATLAB operators, when used to overload default behaviour, as described in Operator Overloading:
    • plus, minus, uminus, uplus,
    • times, mtimes,
    • rdivide, ldivide, mrdivide, mldivide,
    • power, mpower,
    • lt, gt, le, ge, ne, eq, and, or, not,
    • colon,
    • subsref, subsasgn, subsindex,
  • MATLAB functions, related to Customize Object Indexing:
    • listLength,
    • numArgumentsFromSubscript
  • Other MATLAB functions allowed to overload/implement as method:

Other relevant documentation links:

Configurable parameters

  • Exceptions (list): A list of names that do not need to be checked for shadowing. Add names to this list if you want to shadow certain files/functions or if you do not mind shadowing specific files.

Exemption tag: %@ok<NSHAD>