```IsWellKnownTypeUnmanagedType``` helper in `C#` compiler fails to filter out generic types.
- Dominant language
- C#
- Stars
- 20.7k
- Forks
- 4.3k
- PR merge metrics
- PR metrics pending
Description
The following test passes but it should produce an error on ```obj.M1()```:
```
[Fact]
public void LoadingUnmanagedTypeModifier_ModreqGeneric()
{
var ilSource = IsUnmanagedAttributeIL + @"
.class public auto ansi beforefieldinit TestRef
extends [mscorlib]System.Object
{
.method public hidebysig instance void
M1() cil managed
{
.param type T
.custom instance void System.Runtime.CompilerServices.IsUnmanagedAttribute::.ctor() = ( 01 00 00 00 )
// Code size 2 (0x2)
.maxstack 8
IL_0000: nop
IL_0001: ret
} // end of method TestRef::M1
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
// Code size 8 (0x8)
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: nop
IL_0007: ret
} // end of method TestRef::.ctor
}
.class public auto ansi beforefieldinit System.Runtime.InteropServices.UnmanagedType`1
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname
instance void .ctor () cil managed
{
.maxstack 8
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
}
}
";
var reference = CompileIL(ilSource, prependDefaultHeader: false);
var code = @"
public class Test
{
public static void Main()
{
var obj = new TestRef();
obj.M1();
}
}";
CreateCompilation(code, references: new[] { reference }).VerifyDiagnostics(
);
}
```
Other similar helpers should be checked for the same problem.
Contributor guide
Research direction
Start by locating the IsWellKnownTypeUnmanagedType helper in the C# compiler and inspect the LoadingUnmanagedTypeModifier_ModreqGeneric test, including its IL source and CreateCompilation call. Reproduce the case where obj.M1() passes, then check the other similar helpers named by the issue. Done means the repro reports an error and related helper cases are covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- compilers, testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100