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

Various fixes to C# warnings #65532

Closed

Conversation

raulsntos
Copy link
Member

@raulsntos raulsntos commented Sep 8, 2022

Extracted to different PRs

TODO

@@ -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;
Copy link
Contributor

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.");
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

@raulsntos raulsntos Sep 9, 2022

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");
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Member Author

@raulsntos raulsntos Sep 10, 2022

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");
Copy link
Contributor

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
Copy link
Contributor

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'
Copy link
Contributor

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?

@neikeq
Copy link
Contributor

neikeq commented Sep 9, 2022

Fix RS2008: Enable analyzer release tracking.

* Not sure how to fix this one. The quick fix in VSCode does nothing.

I think this is about https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

@neikeq
Copy link
Contributor

neikeq commented Sep 9, 2022

Fix CA1001: Type owns disposable field but is not disposable.

* [ ]  `Array` and `Dictionary`: This was already discussed a bit in

This won't be a simple change. It will require some design decisions.

@raulsntos
Copy link
Member Author

Fix RS2008: Enable analyzer release tracking.

* Not sure how to fix this one. The quick fix in VSCode does nothing.

I think this is about https://github.com/dotnet/roslyn-analyzers/blob/main/src/Microsoft.CodeAnalysis.Analyzers/ReleaseTrackingAnalyzers.Help.md

Yes but since the quick fix doesn't seem to do anything in VSCode, should I create the markdown files manually? Suppress the warning?

Fix CA1001: Type owns disposable field but is not disposable.

* [ ]  `Array` and `Dictionary`: This was already discussed a bit in

This won't be a simple change. It will require some design decisions.

I don't intend to solve this warning in this PR but I wanted to mention it since it's somewhat related.

@raulsntos
Copy link
Member Author

Rebased and extracted breaking changes to #72053.

@akien-mga akien-mga modified the milestones: 4.0, 4.1 Feb 17, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.2 Jun 14, 2023
@raulsntos raulsntos modified the milestones: 4.2, 4.3 Oct 4, 2023
- 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.
@paulloz
Copy link
Member

paulloz commented May 2, 2024

Can we close this one? The only remaining point is the several instances of CA1001, and this PR does not fix them. We should track that particular issue in its own thread instead.

@raulsntos
Copy link
Member Author

Yes, this has been superseded by the multiple PRs that are now linked in the PR description.

@raulsntos raulsntos closed this May 4, 2024
@raulsntos raulsntos deleted the dotnet/various-warnings branch May 4, 2024 02:02
@raulsntos raulsntos removed this from the 4.3 milestone May 4, 2024
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.

Multiple C# classes hiding inherited members in GodotSharp
5 participants