roslyn
roslyn copied to clipboard
Conversions to restricted types are not disallowed in expression trees
We disallow restricted types in expression trees (since https://github.com/dotnet/roslyn/pull/30871). But we exclude conversions to restricted types - https://github.com/dotnet/roslyn/pull/30871#discussion_r230242508 mentions avoiding duplicate diagnostics, but there are other scenarios which result in no diagnostics at all, like:
using System;
using System.Linq.Expressions;
C.R(() => C.M(new string[] { "a" }));
static class C
{
public static void R(Expression<Action> e) => e.Compile()();
public static void M(ReadOnlySpan<string> x) => Console.Write(x[0]);
}
Note that this currently compiles and runs, so fixing this bug would be a breaking change.