Browse Source

Avoid breaking LINQ query expressions with nullable reference types.

pull/4077/head
Daniel Grunwald 2 weeks ago
parent
commit
3d10a04996
  1. 18
      ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullableRefTypes.cs
  2. 2
      ICSharpCode.Decompiler/Semantics/LambdaResolveResult.cs

18
ICSharpCode.Decompiler.Tests/TestCases/Pretty/NullableRefTypes.cs

@ -3,6 +3,7 @@ using System; @@ -3,6 +3,7 @@ using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
{
@ -207,4 +208,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty @@ -207,4 +208,21 @@ namespace ICSharpCode.Decompiler.Tests.TestCases.Pretty
return default;
}
}
public class T09_Linq
{
public IEnumerable<string> QueryWithNonNullableReferenceTypes(IEnumerable<string> strings)
{
return from s in strings
where s.Length > 0
select s.ToUpper();
}
public IEnumerable<string> QueryWithNullableReferenceTypes(IEnumerable<string?> strings)
{
return from s in strings
where s != null
select s.ToUpper();
}
}
}

2
ICSharpCode.Decompiler/Semantics/LambdaResolveResult.cs

@ -165,7 +165,7 @@ namespace ICSharpCode.Decompiler.Semantics @@ -165,7 +165,7 @@ namespace ICSharpCode.Decompiler.Semantics
return Conversion.None;
for (int i = 0; i < parameterTypes.Length; ++i)
{
if (parameterTypes[i].Equals(this.Parameters[i].Type))
if (NormalizeTypeVisitor.IgnoreNullability.EquivalentTypes(parameterTypes[i], this.Parameters[i].Type))
{
continue;
}

Loading…
Cancel
Save