When constructors or functions conflict due to having the same calling signature, they should not be allowed to compile.
This is already the case in most scenarios, but when default arguments cause conflict, the compiler does not catch this issue. Even more so, in the case of constructors, visibility rules are ignored.
Example:
```d
module text;
import std.stdio;
class Text {
string text;
private this(string text) {
writeln("private");
}
this(string filename, string arg2 = ".txt") {
writeln("public");
}
}
```
```d
module app;
void main(){
Text t = new Text("file"); // writes "private"
}
```
Calling `new Text("test")` from anywhere will call the first constructor, ignoring its `private` attribute.
If this is done with functions instead of constructors, the same thing will happen with one exception: the compiler will state the function is not accessible. (It will however try to resolve to the private function, ignoring the accessible alternative)
1. This hints at issues with constructors ignoring visibility attributes!
2. The code should not compile when conflicts occur (even when this is due to default values).
Comment #1 by destructionator — 2023-12-12T17:09:42Z
I think it has to do with overload resolution not considering the visibility
Comment #2 by robert.schadek — 2024-12-13T19:32:09Z