Skip to content
This repository was archived by the owner on Sep 25, 2026. It is now read-only.

ExpectedWarning silences only one warning per attribute - #2479

Merged
tlakollo merged 1 commit into
dotnet:mainfrom
tlakollo:ExpectedWarningSilenceOnlyOneWarning
Jan 5, 2022
Merged

tlakollo merged 1 commit into
dotnet:mainfrom
tlakollo:ExpectedWarningSilenceOnlyOneWarning

Conversation

@tlakollo

@tlakollo tlakollo commented Jan 5, 2022

Copy link
Copy Markdown
Contributor

Previously the ExpectedWarning attribute in linker will silence multiple warnings if they matched the requirements. This allowed duplicated warnings to be generated without noticing. Analyzer silences only one warning per attribute showing some bugs in linker. This PR changes the ExpectedWarning behavior in linker to only silence one warning per attribute.

@tlakollo
tlakollo merged commit 6de0836 into dotnet:main Jan 5, 2022
@tlakollo
tlakollo deleted the ExpectedWarningSilenceOnlyOneWarning branch January 5, 2022 19:13
var matchedMessages = loggedMessages.Where (mc => {
if (mc.Category != MessageCategory.Warning || mc.Code != expectedWarningCodeNumber)
return false;
foreach (var loggedMessage in loggedMessages) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I'd prefer to keep matchedMessages around, since it makes it slightly easier to debug when an attribute matches multiple warnings. Below we could either assert that only one message is matched, or remove just the first match. This also avoids having to repeat expectedWarningFound = true; loggedMessages.Remove (loggedMessage); break; in the code below.

@tlakollo tlakollo Jan 5, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess what I didn't like about matchedMessages is that we loop over all messages (except the ones are being removed), for all attributes. If we already found a match and we know that we can remove only one logged message, why not stop there. But yeah it was convenient that matched messages allow you to run the whole logic and you could review if it matched something or not.
Notice that most messages wont repeat, and yet we will loop over all the messages looking for another match

@sbomer sbomer mentioned this pull request Jan 13, 2022
4 tasks done
agocke pushed a commit to dotnet/runtime that referenced this pull request Nov 16, 2022
Previously the ExpectedWarning attribute in linker silenced multiple warnings if they matched the requirements. This allowed duplicated warnings to be generated without noticing. Analyzer silences only one warning per attribute showing some bugs in linker. This PR changes the ExpectedWarning behavior in linker to only silence one warning per attribute.

Commit migrated from dotnet/linker@6de0836
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants