Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExpectedWarning silences only one warning per attribute #2479

Merged

Conversation

tlakollo
Copy link
Contributor

@tlakollo tlakollo commented Jan 5, 2022

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
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.

Copy link
Contributor Author

@tlakollo tlakollo Jan 5, 2022

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
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 join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants