Open mangod9 opened 2 years ago
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.
@AaronRobinsonMSFT , assume this is ok to close or is there more work required here?
@AaronRobinsonMSFT ping again. Anything remaining for this in 8?
Only the bare minimum has been done. Moving this to .NET 9.
This feature request would be extremely valuable for unit testing. Right now, when using mocking frameworks like NSubstitute it's impossible to mock out a function that takes a ref-struct type like ReadOnlySpan as an argument.
For example doing the following gives a CS0306 error:
interface IMessage
{
string DoSomething(ReadOnlySpan<byte>);
}
// Test Code
IMessage message = Substitute.For<IMessage>();
message.DoSomething(Arg.Any<ReadOnlySpan<byte>>()).Returns("success");
NSubstitute and its parent library Castle.Core have investigated this issue in the past and any fixes seem to have stalled out due to the difficulty of doing this without this language feature.
I believe this feature would fix this unit-testing gap and be a big improvement to the dotnet ecosystem.
cc @steveisok
@AaronRobinsonMSFT - did somebody look if this works with Cecil/Trimmer? It uses different type system and it could get confused on the new pattern.
@AaronRobinsonMSFT - did somebody look if this works with Cecil/Trimmer?
Not that I am aware of. Can I get someone from your side to try this out? What do we need to do to exercise this path? We have several IL based assemblies with the feature enabled we can pass to other tools.
@sbomer - we should be able to add tests for illink - the infra has the setup for IL-based tests. Also round-trip tests of Cecil would be helpful (or through illink, it's kind of the same thing) - to make sure trimmer doesn't corrupt the metadata around this.
Cecil work is at https://github.com/jbevain/cecil/pull/945
It looks like everything is done and this issue can be closed. If I'm mistaken, feel free to reopen.
No, sadly this isn't done. After updating the design and ECMA, more work is needed. I moved to 10.
This is a top-level issue to track supporting ref structs within generics. For additional details refer to https://github.com/dotnet/csharplang/issues/7608 and the older https://github.com/dotnet/csharplang/issues/1148.
ref
fields - https://github.com/dotnet/runtime/issues/63768gpAcceptByRefLike
metadata generic param attributeref structs
to implement interfacesref structs
to use DIM implementations - https://github.com/dotnet/runtime/pull/98070ref structs
to use DIM implementationsSystem.Activator.CreateInstance<T>()
to include theallows ref struct
constraint.