Overload in constructor with incompatible arguments should cause a compler error

(Theo) #1
Constructor Create(s: String; b: String = "");
Constructor Create(s: String; q: String);

Th above compiles without error

0 Likes

(marc hoffman) #2

hmm, indeed it should not. can i get a complete testcase? thanx!

0 Likes

(Theo) #3

The test case:

namespace Test;

interface

type SafeString = unit not nullable String; //alias for not nullable string

type TestClass = public class
  public
//2 or 3 arguments
    Constructor Create(Server: SafeString; Db: SafeString; conId: String = "NoId"); begin end;
//3 or 4 arguments
    Constructor Create(Server: SafeString; Mirror: SafeString; Db: SafeString; conId: String = "NoId"); begin end;
//4 or 5 arguments
    Constructor Create(Server: SafeString; Db: SafeString; UserName: SafeString; Password: SafeString; conId: String = "NoId"); begin end;
//5 or 6 arguments
    Constructor Create(Server: SafeString; Mirror: SafeString; Db: SafeString; UserName: SafeString; Password: SafeString; conId: String = "NoId"); begin end;


end;

Implementation

end.
0 Likes

(RemObjects) #4

Thanks, logged as bugs://82160

0 Likes

(RemObjects) #5

bugs://82160 got closed with status nochangereq.

0 Likes

(Carlo Kok) #6

Oke so this is tricky; these are not actually the same, however I agree the default parameters can’t really be called. the compiler will always prefer fewer parameters to more parameters. The reason we don’t fail on this is because a C# caller CAN call these with named arguments and still use the default argument like:

new TestClass(Server: “”, Db: “”, Mirror: “”) << calls the second overload.

So I fear I have to close this as “can’t fix”.

0 Likes

(marc hoffman) #7

woah, I didn’t know C# supports this!

0 Likes

(Theo) #8

VB.Net does too.
Hint: may be something for Oxygene?

0 Likes

(Theo) #9

Can I get a warning on it?

0 Likes