rspec/rules/S3427/rule.adoc

23 lines
699 B
Plaintext
Raw Normal View History

2020-06-30 12:48:39 +02:00
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.
2021-02-02 15:02:10 +01:00
2020-06-30 12:48:39 +02:00
This rule raises an issue when an overload with default parameter values is hidden by one without the optional parameters.
== Noncompliant Code Example
2022-02-04 17:28:24 +01:00
[source,text]
2020-06-30 12:48:39 +02:00
----
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?
----