Fix #4016: Don't consume nullable flags for anonymous type arguments
Roslyn writes [Nullable] for an anonymous type as if the type was not generic, so its type arguments have no flags. Taking one per argument shifted every annotation after the anonymous type, which showed on the cached lambda fields in <>c, and tripped the dummy-flag assert when the shifted stream landed on a generic struct. [Dynamic] and [TupleElementNames] do have entries for those arguments (checked against what Roslyn emits), so only the nullable index skips them.
This commit is contained in:
1 parent
2dc58c945d
commit
c61379b8b9
3 files changed
+76
-1
No files matched your search
+33
@@ -0,0 +1,33 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace ICSharpCode.Decompiler.Tests.TestCases.IsolatedDecompilation
|
||||
{
|
||||
public class AnonymousTypeNullability
|
||||
{
|
||||
public void ReferenceTypeAfterAnonymousType(IEnumerable<string> xs)
|
||||
{
|
||||
xs.Select(x => new { A = x, B = x }).Pick(a => new List<string?>());
|
||||
}
|
||||
|
||||
public void ValueTypeAfterAnonymousType(IEnumerable<string> xs)
|
||||
{
|
||||
xs.Select(x => new { A = x }).PickPair(a => new KeyValuePair<string, string?>(a.A, null));
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnonymousTypeNullabilityExtensions
|
||||
{
|
||||
public static IEnumerable<T> Pick<TSource, T>(this IEnumerable<TSource> source, Func<TSource, List<T?>> selector) where T : class
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public static IEnumerable<T> PickPair<TSource, T>(this IEnumerable<TSource> source, Func<TSource, KeyValuePair<string, T?>> selector) where T : class
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user