dotnet / dotnet/dotnet-api-docs
Update doc for `OpCodes.Constrained` to "support" static abstract interface members.
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
The [doc](https://learn.microsoft.com/en-us/dotnet/api/system.reflection.emit.opcodes.constrained?view=net-7.0) explicitly says that this opcode can appear only a `callvirt` instruction:
> The `constrained` prefix is permitted only on a `callvirt` instruction.
But according to [sharplab](https://sharplab.io/#v2:C4LglgNgPgAgTARgLACgYAYAEBlAFgQwCcAHAGXwCMA6AJQFcA7YMAWwFMBuVVGAZkzBM2hAGb4Axm0wBJACpsAzsEoQpAb1SYtmPpkpLCE4DoQA2HQBZM8pQAoAlFxQBfbmn7xMAWQCeN4MIAPLIAfJgA7rjCUrKYIDL+Kuqa2rowVvQM/g6YGijaBdZU2Y4pWq4ubkA===) the following:
```csharp
public interface ITestable {
public abstract static void Test();
}
public class MyTester where T : ITestable {
public void RunTest() {
T.Test();
}
}
```
Leads to the following IL:
```il
.method public hidebysig
instance void RunTest () cil managed
{
// Method begins at RVA 0x208e
// Code size 12 (0xc)
.maxstack 8
IL_0000: constrained. !T
IL_0006: call void ITestable::Test()
IL_000b: ret
} // end of method MyTester`1::RunTest
```
Assuming that sharplab is right and this is intended behaviour it seems that update for docs can be needed.
Contributor guide
Assessment
This issue has not been assessed yet.