Browse Source

Fix LambdaResolveResult.IsValid() being too restrictive.

This could cause our overload resolution to consider an overload as not-applicable when it actually is applicable. This could cause us to miss some cases where we need to insert casts.
pull/1730/head
Daniel Grunwald 6 years ago
parent
commit
080f63e660
  1. 9
      ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs
  2. 3
      ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs

9
ICSharpCode.Decompiler.Tests/TestCases/Correctness/TrickyTypes.cs

@ -17,6 +17,7 @@
// DEALINGS IN THE SOFTWARE. // DEALINGS IN THE SOFTWARE.
using System; using System;
using System.Linq;
namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
{ {
@ -27,6 +28,8 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
InterestingConstants(); InterestingConstants();
TruncatedComp(); TruncatedComp();
StringConcat(); StringConcat();
LinqNullableMin();
LinqNullableMin(1, 2, 3);
} }
static void Print<T>(T val) static void Print<T>(T val)
@ -101,5 +104,11 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Correctness
Print(string.Concat(1, 2)); Print(string.Concat(1, 2));
Print(string.Concat(1, 2, "str")); Print(string.Concat(1, 2, "str"));
} }
static void LinqNullableMin(params int[] arr)
{
Print(string.Format("LinqNullableMin {0}:", arr.Length));
Print(arr.Min(v => (int?)v));
}
} }
} }

3
ICSharpCode.Decompiler/CSharp/Resolver/LambdaResolveResult.cs

@ -162,7 +162,8 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
} }
} }
} }
if (conversions.IdentityConversion(returnType, this.ReturnType)) { if (conversions.IdentityConversion(this.ReturnType, returnType)
|| conversions.ImplicitConversion(this.InferredReturnType, returnType).IsValid) {
return LambdaConversion.Instance; return LambdaConversion.Instance;
} else { } else {
return Conversion.None; return Conversion.None;

Loading…
Cancel
Save