Browse Source

Fix comment + LINQ: validate type arguments in ThenBy-chain.

pull/4077/head
Daniel Grunwald 2 weeks ago
parent
commit
99613cc797
  1. 7
      ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs
  2. 4
      ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs

7
ICSharpCode.Decompiler/CSharp/Resolver/TypeInference.cs

@ -1336,8 +1336,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver @@ -1336,8 +1336,11 @@ namespace ICSharpCode.Decompiler.CSharp.Resolver
// Apply the merged top-level nullability:
Debug.Assert(topLevelNullability.HasValue);
// (Roslyn has a different approach in MergeOrRemoveCandidates, but to me that just looked
// like an overly complicated way of achieving the same thing.)
// Roslyn has a different approach in MergeOrRemoveCandidates, which can
// differ in behavior when there's both lower+upper bounds
// -- e.g. `static void M<T>(T x, Action<T> a)` called with `M("s", (object? o) => {}))`
// is inferred as `T = object?` by Roslyn, but `T = object` by us.
// To match Roslyn exactly, we'd need to handle the topLevelNullability per-candidate.
for (int i = 0; i < candidateTypes.Count; i++)
{
candidateTypes[i] = candidateTypes[i].ChangeNullability(topLevelNullability.Value);

4
ICSharpCode.Decompiler/CSharp/Transforms/IntroduceQueryExpressions.cs

@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -348,7 +348,7 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
static bool IsComplexQuery(MemberReferenceExpression mre)
{
return ((mre.Target is InvocationExpression && mre.Parent is InvocationExpression) || mre.Parent?.Parent is QueryClause);
return (mre.Target is InvocationExpression && mre.Parent is InvocationExpression) || mre.Parent?.Parent is QueryClause;
}
QueryFromClause MakeFromClause(ParameterDeclaration parameter, Expression body)
@ -414,6 +414,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms @@ -414,6 +414,8 @@ namespace ICSharpCode.Decompiler.CSharp.Transforms
return false;
if (parameter.Name != expectedParameterName)
return false;
if (mre.TypeArguments.Count > 0)
return false;
if (mre.MemberName == "OrderBy" || mre.MemberName == "OrderByDescending")
return !IsNullConditional(mre.Target);

Loading…
Cancel
Save