dotnet / dotnet/linker

Trimmer-safety analyzer misses RUC members on base types kept through DAM attributes

Open
#3,111 3 comments 0 reactions 0 assignees View on GitHub
area-Analyzers
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

Given the following code, the trimmer will issue a warning at trim time, but the Roslyn analyzer won't warn.

```csharp
class Foo
{
[RequiresUnreferencedCode("")]
public static void Bar() {}
}

class Bar : Foo
{
}

class Test
{
public static void Method()
{
Method2(typeof(Bar<>)); // Warns here in the linker, but not in the analyzer
}

private static void Method2([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicMethods)] Type type) {}
}
```

We traced this down to the behavior in Roslyn around "unbound constructed generic types", or more specifically `Bar<>`, as compared to `Bar`. `Bar` is the original definition and has full fidelity in the Roslyn type system. However, `Bar<>` is considered an "unbound constructed generic" and as a result has [a few limitations](https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.inamedtypesymbol.isunboundgenerictype?view=roslyn-dotnet-4.3.0) in the Roslyn type system.

These limitations cause this particular case to be missed by the analyzer built on top of the Roslyn type system, whereas the Cecil type system captures this case.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.