Hi,
I was trying out Visual Studio for mac. I have code of this form in my projects:
using System;
public class MyClass
{
public MyClass ()
{
Outer (Inner);
}
void Inner () { }
void Outer(Action inner){inner ();}
void Outer(Func<MyClass> inner){inner ();}
}
that compiles and runs fine with Monodevelop-Unity from 5.6.2 but gives this error when compiled with VS:
/Users/***/Projects/TestOverload/TestOverload/MyClass.cs(4,4): Error CS0121: The call is ambiguous between the following methods or properties: 'MyClass.Outer(Action)' and 'MyClass.Outer(Func<MyClass>)' (CS0121) (TestOverload)
I also tried with .net 4.6 runtime in Unity 2017.1 and it compiles in both monodevelop and unity
Is this a breaking change that we should be aware of when you will upgrade to Roslyn?
We’ll keep an eye on it for the Roslyn upgrade. Usually Roslyn is more correct than the Mono C# compiler (mcs) in cases like this, so it might be a valid error from Roslyn.
currently mono picks the expected overload ( void Outer (Action inner) { inner (); } ) and compiles.
some more cases:
if Inner is " MyClass Inner () { … } " both mono and VS compile (picking the Func<> overload)
if we add a third overload " void Outer (Func inner) { inner (); } " mono still compile, but roslyn throws an ambiguity between " void Outer (Func inner) " and " void Outer (Func inner) "
2.1) void Inner() {} still causes ambiguity between the first 2 overload declared.
point 1 seems a little strange. why some candidates can be picked but others can’t?
I also compile directly in the IDE (via cmd-B hotkey) when writing code going back to Unity only when I am done)
I also have separate DLLs for stuff that doesn’t depend on Unity