Repository navigation
Fixes a null-ref/NotSupportedException in warning infra - #2396
Conversation
If we end up marking a type due to descriptor and the type marking will cause a warning (for example a removed attribute type does this in some cases), the warning infra would fail. This is because it requires all warnings to have a valid origin including which assembly it came from. But descriptors didn't provide this information. Most of the change here are to fix that lack of information. When marking through annotations, we now store the message origin for the mark operation along with the target of the marking. This is then restored on the scope stack to be used when reporting warnings caused by such marking. This required lot of changes to pass the message origin in all places which end up marking things in annotations. This also required some small fixes as it uncovered previously unseen issues. Additionally, it can still happen that there's really no origin (for example copy action specified on command line will mark entire assembly - there's nothing to blame, but the command line) for a message or we can't assign an assembly (descriptor file pass on the command line, we can blame the file, but we still don't have an assembly). So this change tweaks the warning infra to allow messages without assembly of origin. Enabled a test whcih validated the behavior around removed attribute being marked via descriptor (this now produces warning with fully valid origin). Added another test where the warning is due to a descriptor on command line (no associated assembly for such warning).
|
|
||
| // The assembly attribute should be specified if available as it allows assigning the diagnostic | ||
| // to a an assembly (we group based on assembly). | ||
| public MessageOrigin (string fileName, int sourceLine, int sourceColumn, AssemblyDefinition? assembly) |
There was a problem hiding this comment.
Can you make AssemblyDefinition non-nullable? I think in this advanced ctor it would make more sense.
There was a problem hiding this comment.
Unfortunately not. The case where the null happens here is command line specified descriptor xml. Warnings from it have file name, and line/col numbers, but no assembly. It's a valid case and the code actually handles it. The "field" test I added tests for exactly that case.
| // Add an empty record - this prevents reentrancy | ||
| // If the embedded XML itself generates warnings, trying to log such warning | ||
| // may ask for attributes (suppressions) and thus we could end up in this very place again | ||
| // So first add a dummy record and once processed we will replace it with the real data |
There was a problem hiding this comment.
Makes sense, but this scares me 😨
There was a problem hiding this comment.
Yeah - I'm not happy about it either. I did go through the code which can run here, and there's only very few places where we generate warnings, so it's not that bad. Maybe we should think about this some more how to solve - but this is hard, we want to be lazy about the suppressions (too expensive to do eagerly).
…r#2396) If we end up marking a type due to descriptor and the type marking will cause a warning (for example a removed attribute type does this in some cases), the warning infra would fail. This is because it requires all warnings to have a valid origin including which assembly it came from. But descriptors didn't provide this information. Most of the change here are to fix that lack of information. When marking through annotations, we now store the message origin for the mark operation along with the target of the marking. This is then restored on the scope stack to be used when reporting warnings caused by such marking. This required lot of changes to pass the message origin in all places which end up marking things in annotations. This also required some small fixes as it uncovered previously unseen issues. Additionally, it can still happen that there's really no origin (for example copy action specified on command line will mark entire assembly - there's nothing to blame, but the command line) for a message or we can't assign an assembly (descriptor file pass on the command line, we can blame the file, but we still don't have an assembly). So this change tweaks the warning infra to allow messages without assembly of origin. Enabled a test whcih validated the behavior around removed attribute being marked via descriptor (this now produces warning with fully valid origin). Added another test where the warning is due to a descriptor on command line (no associated assembly for such warning). Commit migrated from dotnet/linker@4e77a94
If we end up marking a type due to descriptor and the type marking will cause a warning (for example a removed attribute type does this in some cases), the warning infra would fail.
This is because it requires all warnings to have a valid origin including which assembly it came from. But descriptors didn't provide this information.
Most of the change here are to fix that lack of information. When marking through annotations, we now store the message origin for the mark operation along with the target of the marking. This is then restored on the scope stack to be used when reporting warnings caused by such marking.
This required lot of changes to pass the message origin in all places which end up marking things in annotations.
This also required some small fixes as it uncovered previously unseen issues.
Additionally, it can still happen that there's really no origin (for example copy action specified on command line will mark entire assembly - there's nothing to blame, but the command line) for a message or we can't assign an assembly (descriptor file pass on the command line, we can blame the file, but we still don't have an assembly).
So this change tweaks the warning infra to allow messages without assembly of origin.
Enabled a test whcih validated the behavior around removed attribute being marked via descriptor (this now produces warning with fully valid origin).
Added another test where the warning is due to a descriptor on command line (no associated assembly for such warning).
This fixes the linker issue found in #2358.