mono - C# MonoTouch method overload with Generic method and Non-generic method with default argument -


.. and one side of potato.

I have a codebase that I am compiling for both Windows and Monochouch in the morning, I have coded some examples of failing windows when compiling on Monochach:

  void run () {// ok both exec ("hello", 1); // ok on mono-heel / compiler error on windows exec ("hello"); } Interface iFace {void foo (); } Zero exec (string s, int n = 0) {console.Write ("a"); } Zero exec & lt; T & gt; (TT) where T: IFace {Console.Write ("B"); }   

On mono-touch, it compiles and runs, printing:

  aa   

On Windows, this Example gives a compile-time error:

Type 'string' is the default type or method 'App.Program.exec & lt; T & gt; (T) 'type parameter can not be used as' T'. There is no underlying reference conversion in 'approgram.efpress' from 'string'.

It says at C # spec that there should be an equal number of arguments:

A number of arguments in the function of the number of parameters in the member declaration are equal.

It appears that the MonoTouch compiler is considering the default arguments while searching the applicable function members, but the Windows compiler is not. Therefore the candidate function members are:

  // exec is not implemented with no default parameters because no injection is zero exec (string, int); The default value for the second parameter is // exec. // Only monochach was considered zero exec (string, int = 0); // Normal exec with string as typed, which is invalid due to IFace constraint // invalid on both platforms zero execut & lt; String & gt; (String): where T: IFace;   

So is this a function applied on mono-touch to a bug in the member search, or does the Windows compiler consider a default-parameter non-default method valid?

Cheers, cm

Edit after answering dlev , I tested both constrained and uncontrolled generic methods and It seems that the mono compiler chooses the right method in the unbalanced case. In the constraints case, it seems that the mono compiler is either considering hurdles or back-tracking when the obstacle fails.

Reduces the problem / bug:

  Run zero () {EFU (1); Bar (1); } Zero foo (int a, int b = 0) {print ("a"); } Zero foo & lt; T & gt; (Tt) {print ("b"); } Zero times (int a, int b = 0) {print ("X"); } Zero times & lt; T & gt; (TT) ou T: IFace {print ("Y"); }   

prints foo correctly B , on both Windows and Monochach. But failing to compile on the bar , Windows prints X on Monochach.

EDIT2 For those interests, my solution requires the removal of the default parameters and requires explicit invitations in my actual system, the type barrier specifies two interfaces, so I Exec (IFace t) {...} can not easily replace the normal call I think I can react, but it is the meat of my system and my existing compilation problems have been solved by following:

  zero exec (string a) {exec (a, 0); } Zero exec (string a, int b) {...} zero exec & lt; T & gt; (TT) where T: IFace, IFace2 {...}   

Double cheers, cm

This line tells section 7.5.3.2 that this is a bug in the mono compiler:

Otherwise if there was a similar logic with all MPs' criteria , Then the original arguments should be replaced in MQ for at least one optional parameter, then MQ is better than MQ.

In other words, if you have to optionally consider the value of an optional parameter to make a duly method, then that method is considered to be a bad match, whose such Replacement is not required.

In addition, once deciding the best method according to the surcharge resolution rules, the compilation continues under that assumption. If the analysis later determines that the method chosen method results in an error (because this substitution general argument violates an obstruction), then you are told about that error.

And, therefore the overload resolution T .

Comments