roslyn icon indicating copy to clipboard operation
roslyn copied to clipboard

Conversions to restricted types are not disallowed in expression trees

Open jjonescz opened this issue 8 months ago • 4 comments

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]);
}

SharpLab

Note that this currently compiles and runs, so fixing this bug would be a breaking change.

jjonescz avatar Jun 25 '24 14:06 jjonescz