-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Labels
Area-CompilersFeature - Warning WavesWarning WavesWarning WavesFeature Requesthelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it
Milestone
Description
The following code compiles, but throws a TypeLoadException
when executed.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var x = MyStruct.Empty;
}
public struct MyStruct
{
public static readonly MyStruct? Empty = null;
}
}
}
Since Empty
is static, this is not a cyclic struct layout issue. It would be nice if the compiler produced warnings that tells you that you are likely to run into this CLR bug at runtime
[Note from @gafter this is due to CLR bug https://github.com/dotnet/coreclr/issues/4049. See also https://github.com/dotnet/coreclr/issues/7957 and https://github.com/dotnet/coreclr/issues/22553 for other situations where the warning would be helpful]
sdcb and DaveCousineau
Metadata
Metadata
Assignees
Labels
Area-CompilersFeature - Warning WavesWarning WavesWarning WavesFeature Requesthelp wantedThe issue is "up for grabs" - add a comment if you are interested in working on itThe issue is "up for grabs" - add a comment if you are interested in working on it