Linker produces warnings for removed code
- Dominant language
- C#
- Stars
- 392
- Forks
- 128
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 2
Description
In general we have been designing the linker warnings so that they are only shown for used code. However, there are a few warnings which may be shown even for unused code. One example is IL2099 which is [produced](https://github.com/dotnet/linker/blob/6880454ee1a29cb9e8239cb28d352228712661ee/src/linker/Linker.Dataflow/FlowAnnotations.cs#L311) when building flow annotations, regardless of whether the member in question is ultimately marked.
There is a case in the test checker that allows warnings which originate from removed code. Since we collect the cecil object as part of the message origin and then later "detach" it from the module when it's removed, when comparing the expected vs actual message origin we handle the case where the origin has no DeclaringType:
https://github.com/dotnet/linker/blob/6880454ee1a29cb9e8239cb28d352228712661ee/test/Mono.Linker.Tests/TestCasesRunner/ResultChecker.cs#L1071-L1075
Removing this case causes just one test to fail (when I checked) - this test expects a warning from unused code https://github.com/dotnet/linker/blob/6880454ee1a29cb9e8239cb28d352228712661ee/test/Mono.Linker.Tests.Cases/DataFlow/PropertyDataFlow.cs#L45
but the property is removed in `CleanStep`.
@jtschuster also hit a similar case with an `ExpectedWarning` on an unused override method, so presumably the override validation warnings can be produced for unused code. Indeed, it looks like we consider all overrides here, not just marked ones: https://github.com/dotnet/linker/blob/6880454ee1a29cb9e8239cb28d352228712661ee/src/linker/Linker.Steps/ValidateVirtualMethodAnnotationsStep.cs#L24-L34
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.