-
-
Notifications
You must be signed in to change notification settings - Fork 20.2k
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
Various fixes to C# warnings #65532
Various fixes to C# warnings #65532
Conversation
modules/mono/editor/Godot.NET.Sdk/Godot.SourceGenerators/Godot.SourceGenerators.csproj
Outdated
Show resolved
Hide resolved
@@ -47,9 +47,9 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context) | |||
var typeSymbol = sm.GetSymbolInfo(typeSyntax).Symbol as ITypeSymbol; | |||
Debug.Assert(typeSymbol != null); | |||
|
|||
var parentSymbol = sm.GetSymbolInfo(parentSyntax).Symbol; | |||
var parentSymbol = sm.GetSymbolInfo(parentSyntax!).Symbol; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If all these come from the Debug.Assert
, then I think it would be better to do "if null throw". This way, you can also include useful information if the value happen to be null.
However, if those don't come from previous assertions, I would be very careful about that. I would only do that if it's very clear the value cannot be null.
@@ -135,7 +136,9 @@ INamedTypeSymbol symbol | |||
|
|||
source.Append("#pragma warning disable CS0109 // Disable warning about redundant 'new' keyword\n"); | |||
|
|||
source.Append($" public new class MethodName : {symbol.BaseType.FullQualifiedName()}.MethodName {{\n"); | |||
Debug.Assert(symbol.BaseType != null, "Symbol always has a base type because every script class must inherit from a Godot type; otherwise, the generator wouldn't be visiting this class."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really don't like the fact flow analysis can't understand the value cannot be null after this check in .NET Standard 2.0. I think throwing an exception would be better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, wouldn't this check be excluded when publishing the package?
[System.Diagnostics.Conditional("DEBUG")]
public static void Assert (bool condition);
Calls to this function are only compiled in Debug configurations. It's the same as:
#if DEBUG
Debug.Assert(foo);
#endif
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the call is excluded, that's why I'm using it in these cases because they will never be null so I wanted to avoid the unnecessary check but it might still be useful during development to notice if we're doing something wrong.
In this case, since we are filtering the classes with SelectGodotScriptClasses
these classes must always inherit from at least Godot.Object
so the symbol.BaseType
will never be null.
"'Missing XML comment for publicly visible type or member'\n"); | ||
"'Missing XML comment for publicly visible type or member'\n" | ||
"#pragma warning disable CA1716 // Disable warning: " | ||
"'Identifiers should not match keywords'\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how to feel about this. I would like to keep this in sight. We may want to rename those in the future. The Object one if fine to disable, because it's very obvious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be done inside an #if
? If so, we could have a configuration to enable this warning, while having it disabled by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It can and it sounds good to me. I don't really want to suppress these warnings but solving them properly would require renaming which seems unlikely to happen in a timely manner and after the beta we won't want to break compatibility.
I've surrounded all these suppressions like so:
#if !EXTRA_WARNINGS
#pragma warning disable CA1716
#endif
"#pragma warning disable CS1573 // Disable warning: " | ||
"'Parameter has no matching param tag in the XML comment'\n"); | ||
"#pragma warning disable CA1716 // Disable warning: " | ||
"'Identifiers should not match keywords'\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Can CS0108
and CA1716
be done inside an #if
?
@@ -5,6 +5,9 @@ | |||
using System.Runtime.CompilerServices; | |||
using Godot.NativeInterop; | |||
|
|||
// Suppress warning because it complaints about Array not having the Collection suffix. | |||
#pragma warning disable CA1710 // Identifiers should have correct suffix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nonsense warning. We may want to disable it directly in .editorconfig
.
@@ -1,6 +1,8 @@ | |||
using System; | |||
using Godot.NativeInterop; | |||
|
|||
#pragma warning disable CA1716 // Disable warning: 'Identifiers should not match keywords' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto. Can this be done inside an #if
?
modules/mono/glue/GodotSharp/GodotSharp/Core/GodotSynchronizationContext.cs
Outdated
Show resolved
Hide resolved
I think this is about https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md |
This won't be a simple change. It will require some design decisions. |
Yes but since the quick fix doesn't seem to do anything in VSCode, should I create the markdown files manually? Suppress the warning?
I don't intend to solve this warning in this PR but I wanted to mention it since it's somewhat related. |
3bfb090
to
c58945b
Compare
c58945b
to
69b8697
Compare
Rebased and extracted breaking changes to #72053. |
- Suppress REFL045 in a false positive scenario. - Suppress CS0108 caused by shadowing members in derived classes. - Move CA1716 to pragmas in order to allow re-enabling it with a custom define.
69b8697
to
ec730d8
Compare
Can we close this one? The only remaining point is the several instances of |
Yes, this has been superseded by the multiple PRs that are now linked in the PR description. |
Extracted to different PRs
.editorconfig
setup inmodules/mono/
#88570.GodotSynchronizationContext
(and make it sealed).GodotSynchronizationContext
class and related #72053.NotificationSceneInstantiated
in the documentation.NOTIFICATION_INSTANCED
toNOTIFICATION_SCENE_INSTANTIATED
#64410.TODO
Array
andDictionary
: This was already discussed a bit in Merge .NET 6 branch with master #64089 (comment) but I think it's not as straightforward as the rest of the fixes and it should probably be handled in a separate PR.Variant
: It already implementsIDisposable
so I don't know why it complains.