Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3427

Method overloads with default parameter values should not overlap

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Hide
      * This method signature overlaps the one defined on line n [in "filename"], the default parameter value can only be used with named arguments.
      * This method signature overlaps the one defined on line n [in "filename"], the default parameter value can't be used.
      Show
      * This method signature overlaps the one defined on line n [in "filename"], the default parameter value can only be used with named arguments. * This method signature overlaps the one defined on line n [in "filename"], the default parameter value can't be used.
    • Highlighting:
      Hide

      First default parameter value

      Show
      First default parameter value
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C++
    • Covered Languages:
      C#
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      10min
    • Analysis Scope:
      Main Sources, Test Sources
    • ReSharper:
      MethodOverloadWithOptionalParameter

      Description

      The rules for method resolution are complex and perhaps not properly understood by all coders. Having overloads with optional parameter values makes the matter even harder to understand.

      This rule raises an issue when an overload with default parameter values is hidden by one without the optional parameters.

      Noncompliant Code Example

      public class MyClass
      {
        void Print(string[] messages) {...} 
        void Print(string[] messages, string delimiter = "\n") {...} // Noncompliant; default parameter value is hidden by overload
      }
      
      // ...
      MyClass myClass = new MyClass();
      
      myClass.Print(new string[3] {"yes", "no", "maybe"});  // which version of Print will be called?
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              tamas.vajk Tamas Vajk (Inactive)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: