ashmind / SharpLab

.NET language playground
https://sharplab.io
BSD 2-Clause "Simplified" License
2.73k stars 202 forks source link

Combination ref struct and ref parameter causes type constraint IL verification errors #1328

Open mikernet opened 9 months ago

mikernet commented 9 months ago

Description

Combination of ref struct and ref parameters causes validation to fail for the code below. Making BinaryReader a normal non-ref struct or making the parameters non-ref causes the validation error to go away.

Reproduction Steps

Sharplab link

ref struct BinaryReader {}

static class IntProcessor
{
    public static void Read(ref BinaryReader reader)
    {
    }
}

public static class Program {
    public static void Main() {
        BinaryReader reader = new();
        IntProcessor.Read(ref reader);
    }
}

Configuration

.NET 8.0.0