Repository navigation
Check target of module/assembly level suppressions - #2129
Conversation
…essWarningsInModule.cs Co-authored-by: Sven Boemer <[email protected]>
|
|
||
| if (info.Target == null || info.Scope == null) | ||
| if (info.Target == null || scope == null) | ||
| continue; |
There was a problem hiding this comment.
Should null Target or Scope be warnings too?
There was a problem hiding this comment.
I don't see why we should. Both parameters are only relevant for global suppressions, which should always look like [assembly: Unc.../[module: Unc..., and then I think it's reasonable to put the suppression on the module whenever neither are specified. Having a non-module scope without a target could be a case where I think a warning makes sense, e.g. [module: USM("", "", Scope = "type")], I haven't tried this but I think this would actually throw from DocumentationSignatureParser :/
There was a problem hiding this comment.
We should add tests for all these cases - to validate the current behavior. And if some of those behaviors seem broken, either fix it or file new bugs. But have them "verified" by tests regardless.
There was a problem hiding this comment.
Added some tests and changed the DocumentationSignatureParser so that we don't throw when module or id are null.
I wonder if we really need to support global suppressions for a whole assembly. It feels like too easy of a trap to fall into. Maybe if we need to support this, we could write a special rule into the Roslyn analyzer that warns for |
I like this - also as a way to gather more data - if there are actual use cases for assembly level suppressions, we can always just remove this analyzer warning (or scope it better). |
| return _suppressions.TryGetValue (provider, out var suppressions) && | ||
| suppressions.TryGetValue (id, out info); | ||
| suppressions.TryGetValue (id, out info) && | ||
| (provider is ModuleDefinition || provider is AssemblyDefinition ? info.Target == null : true); |
There was a problem hiding this comment.
Why is this necessary - the code in LookForModuleLevelAndGlobalSuppressions will only add the suppression to the list if
- Target is null and provider is module or assembly
- Target is not null, but then provider is not module or assembly
In which case do we need this additional condition?
There was a problem hiding this comment.
Good call. I was hitting this whenever a global suppression was being added from MarkStep https://github.com/mono/linker/blob/41fd293dda27c099b063f51d8917e607271a508e/src/linker/Linker.Steps/MarkStep.cs#L811-L812
Changed things there so that that path isn't followed for global suppressions, otherwise we'd hit this (having suppressions where the provider is a module/assembly and it has a target).
Add tests
* Check that global level suppressions do not specify any target * Run lint * Update test/Mono.Linker.Tests.Cases/Warnings/WarningSuppression/SuppressWarningsInModule.cs Co-authored-by: Sven Boemer <[email protected]> * Add code snippet with an example of 2108. * PR feedback Add tests * Lint * Don't silently suppress warnings on module if scope is missing and a target was used. Co-authored-by: Sven Boemer <[email protected]> Commit migrated from dotnet/linker@b950192
The
Scopeparameter is only relevant in the context of global suppressions (put in a module or an assembly); and the only scopes that we support aremodule,typeandmember. Whenever the scope is set to a value other than these three, we log a message stating that the used argument is not supported -- this was changed to log a warning instead.Unconditional suppressions put on a module/assembly that specify a target are registered as if they were put on the target (e.g., on a type, field, etc.); thus, when looking if a warning is suppressed on a global level, we must make sure to only look in global suppressions that do not specify a target -- this was fixed.