-
Notifications
You must be signed in to change notification settings - Fork 580
[Mono.Android] Fix generated code build warnings #12835
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
Closed
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
f640fd4
[Mono.Android] Fix handwritten build warnings
simonrozsival 1a85823
[Mono.Android] Fix generated code build warnings
simonrozsival 9d793e5
Replace blanket pragma with computed, per-member suppressions
simonrozsival ec1acc4
Finish generator fixes: Mono.Android builds warning-free
simonrozsival e73fc54
Stop emitting suppressions the compiler does not need
simonrozsival ecbf7f9
[generator] only suppress nullability mismatches the compiler reports
simonrozsival 4640635
[generator] apply the obsolete-type gate to every CS0618 site
simonrozsival 9aba482
[generator] narrow the last two over-broad suppression predicates
simonrozsival a1bbc88
[generator] make suppression scopes nest safely and drop type-wide sc…
simonrozsival b494bf8
[Mono.Android] repair the API-37.1 and API-37.2 public API baselines
simonrozsival e5086dc
[generator] test the warning suppression policy directly
simonrozsival File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
external/Java.Interop/src/Xamarin.SourceWriter/Models/WarningSuppression.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
|
|
||
| namespace Xamarin.SourceWriter | ||
| { | ||
| // A single compiler diagnostic that has to be suppressed around one generated member, | ||
| // together with the reason it cannot be avoided. Suppressions are deliberately scoped to | ||
| // the member that needs them so that the same diagnostic elsewhere still breaks the build. | ||
| public class WarningSuppression | ||
| { | ||
| public string Code { get; } | ||
| public string Reason { get; } | ||
|
|
||
| public WarningSuppression (string code, string reason) | ||
| { | ||
| Code = code ?? throw new ArgumentNullException (nameof (code)); | ||
| Reason = reason ?? throw new ArgumentNullException (nameof (reason)); | ||
| } | ||
| } | ||
|
|
||
| // Implemented by the writers that can emit a member-scoped `#pragma warning disable`. | ||
| public interface ISuppressWarnings | ||
| { | ||
| List<WarningSuppression> SuppressWarnings { get; } | ||
| } | ||
|
|
||
| // A standalone set of suppressions, for the generated constructs that are written | ||
| // directly to a `CodeWriter` instead of through a writer that implements | ||
| // `ISuppressWarnings`. | ||
| public class WarningSuppressionScope : ISuppressWarnings | ||
| { | ||
| public List<WarningSuppression> SuppressWarnings { get; } = new List<WarningSuppression> (); | ||
| } | ||
|
|
||
| public static class WarningSuppressionExtensions | ||
| { | ||
| public static void WriteSuppressWarningsStart (this ISuppressWarnings self, CodeWriter writer) | ||
| { | ||
| foreach (var suppression in Ordered (self)) { | ||
| // The writer tracks how deeply each code is nested, so a member inside an | ||
| // already-suppressed scope does not emit a redundant pair that would end the | ||
| // enclosing suppression when it is restored. | ||
| if (!writer.BeginWarningSuppression (suppression.Code)) | ||
| continue; | ||
|
|
||
| writer.WriteLine ($"// {suppression.Reason}"); | ||
| writer.WriteLine ($"#pragma warning disable {suppression.Code}"); | ||
| } | ||
| } | ||
|
|
||
| public static void WriteSuppressWarningsEnd (this ISuppressWarnings self, CodeWriter writer) | ||
| { | ||
| foreach (var suppression in Ordered (self).Reverse ()) { | ||
| if (!writer.EndWarningSuppression (suppression.Code)) | ||
| continue; | ||
|
|
||
| writer.WriteLine ($"#pragma warning restore {suppression.Code}"); | ||
| } | ||
| } | ||
|
|
||
| // The same diagnostic can be reported for more than one reason on a single member, | ||
| // so each code is emitted once, with the reasons combined. | ||
| static IList<WarningSuppression> Ordered (ISuppressWarnings self) => | ||
| self.SuppressWarnings | ||
| .GroupBy (s => s.Code) | ||
| .OrderBy (g => g.Key, StringComparer.Ordinal) | ||
| .Select (g => g.Count () == 1 | ||
| ? g.First () | ||
| : new WarningSuppression (g.Key, string.Join (" ", g.Select (s => s.Reason).Distinct ()))) | ||
| .ToList (); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.