-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Document C# diagnostics #7781
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
Merged
Merged
Document C# diagnostics #7781
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| GD0001: Missing partial modifier on declaration of type which is a subclass of GodotObject | ||
| ========================================================================================== | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0001 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Non-breaking | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| A type that derives from ``GodotObject`` is not declared partial. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot source generators add generated code to user-defined types to implement | ||
| the integration with the engine. Source generators can't add generated code to | ||
| types that aren't declared partial. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| // The source generators can't enhance this type to work with Godot. | ||
| public class InvalidNode : Node { } | ||
|
|
||
| // The source generators can enhance this type to work with Godot. | ||
| public partial class ValidNode { } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, add the ``partial`` keyword to the type | ||
| declaration. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Types that derive from ``GodotObject`` | ||
| but aren't partial can't be enhanced by the source generators, resulting in | ||
| unexpected runtime errors. |
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,52 @@ | ||
| GD0002: Missing partial modifier on declaration of type which contains one or more subclasses of GodotObject | ||
| ============================================================================================================ | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0002 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Non-breaking | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| A type that derives from ``GodotObject`` is contained in a non-partial type declaration. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot source generators add generated code to user-defined types to implement | ||
| the integration with the engine. Source generators can't add generated code to | ||
| types that aren't declared partial. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| public class InvalidParentType | ||
| { | ||
| // MyNode is contained in a non-partial type so the source generators | ||
| // can't enhance this type to work with Godot. | ||
| public partial class MyNode : Node { } | ||
| } | ||
|
|
||
| public partial class ValidParentType | ||
| { | ||
| // MyNode is contained in a partial type so the source generators | ||
| // can enhance this type to work with Godot. | ||
| public partial class MyNode : Node { } | ||
| } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, add the ``partial`` keyword to the type | ||
| declaration. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Types that derive from ``GodotObject`` | ||
| but aren't partial can't be enhanced by the source generators, resulting in | ||
| unexpected runtime errors. | ||
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,46 @@ | ||
| GD0101: Attempted to export static member | ||
| ========================================= | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0101 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Breaking - If the ``static`` keyword is removed | ||
|
|
||
| Non-breaking - If the ``[Export]`` attribute is removed | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| A static member is annotated with the ``[Export]`` attribute. Static members | ||
| can't be exported. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot doesn't allow exporting static members. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| // Static members can't be exported. | ||
| [Export] | ||
| public static int InvalidProperty { get; set; } | ||
|
|
||
| // Instance members can be exported. | ||
| [Export] | ||
| public int ValidProperty { get; set; } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, remove the ``[Export]`` attribute or remove the | ||
| ``static`` keyword. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Static members can't be exported so | ||
| they will be ignored by Godot, resulting in runtime errors. |
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,50 @@ | ||
| GD0102: The type of the exported member is not supported | ||
| ======================================================== | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0102 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Breaking - If the member type is changed | ||
|
|
||
| Non-breaking - If the ``[Export]`` attribute is removed | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| An unsupported type is specified for a member annotated with the ``[Export]`` | ||
| attribute when a :ref:`Variant-compatible <doc_c_sharp_variant>` type is expected. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Every exported member must be Variant-compatible so it can be marshalled by | ||
| the engine. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| class SomeType { } | ||
|
|
||
| // SomeType is not a valid member type because it doesn't derive from GodotObject, | ||
| // so it's not compatible with Variant. | ||
| [Export] | ||
| public SomeType InvalidProperty { get; set; } | ||
|
|
||
| // System.Int32 is a valid type because it's compatible with Variant. | ||
| [Export] | ||
| public int ValidProperty { get; set; } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, change the member's type to be Variant-compatible | ||
| or remove the ``[Export]`` attribute. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Members with types that can't be marshalled | ||
| will result in runtime errors. |
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,55 @@ | ||
| GD0103: The exported member is read-only | ||
| ======================================== | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0103 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Non-breaking | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| A read-only member is annotated with the ``[Export]`` attribute. Read-only members | ||
| can't be exported. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot doesn't allow exporting read-only members. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| // Read-only fields can't be exported. | ||
| [Export] | ||
| public readonly int invalidField; | ||
|
|
||
| // This field can be exported because it's not declared 'readonly'. | ||
| [Export] | ||
| public int validField; | ||
|
|
||
| // Read-only properties can't be exported. | ||
| [Export] | ||
| public int InvalidProperty { get; } | ||
|
|
||
| // This property can be exported because it has both a getter and a setter. | ||
| [Export] | ||
| public int ValidProperty { get; set; } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule for fields, remove the ``readonly`` keyword or | ||
| remove the ``[Export]`` attribute. | ||
|
|
||
| To fix a violation of this rule for properties, make sure the property declares | ||
| both a getter and a setter, or remove the ``[Export]`` attribute. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Read-only members can't be exported so | ||
| they will be ignored by Godot, resulting in runtime errors. |
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,46 @@ | ||
| GD0104: The exported property is write-only | ||
| =========================================== | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0104 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Non-breaking | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| A write-only property is annotated with the ``[Export]`` attribute. Write-only properties | ||
| can't be exported. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot doesn't allow exporting write-only properties. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| private int _backingField; | ||
|
|
||
| // Write-only properties can't be exported. | ||
| [Export] | ||
| public int InvalidProperty { set => _backingField = value; } | ||
|
|
||
| // This property can be exported because it has both a getter and a setter. | ||
| [Export] | ||
| public int ValidProperty { get; set; } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, make sure the property declares | ||
| both a getter and a setter, or remove the ``[Export]`` attribute. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Write-only members can't be exported so | ||
| they will be ignored by Godot, resulting in runtime errors. |
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,44 @@ | ||
| GD0105: Attempted to export indexer property | ||
| ============================================ | ||
|
|
||
| ==================================== ====================================== | ||
| Value | ||
| ==================================== ====================================== | ||
| **Rule ID** GD0105 | ||
| **Category** Usage | ||
| **Fix is breaking or non-breaking** Non-breaking | ||
| **Enabled by default** Yes | ||
| ==================================== ====================================== | ||
|
|
||
| Cause | ||
| ----- | ||
|
|
||
| An indexer is annotated with the ``[Export]`` attribute. Indexers can't be exported. | ||
|
|
||
| Rule description | ||
| ---------------- | ||
|
|
||
| Godot doesn't allow exporting indexer properties. | ||
|
|
||
| .. code-block:: csharp | ||
|
|
||
| private int[] _backingField; | ||
|
|
||
| // Indexers can't be exported. | ||
| [Export] | ||
| public int this[int index] | ||
| { | ||
| get => _backingField[index]; | ||
| set => _backingField[index] = value; | ||
| } | ||
|
|
||
| How to fix violations | ||
| --------------------- | ||
|
|
||
| To fix a violation of this rule, remove the ``[Export]`` attribute. | ||
|
|
||
| When to suppress warnings | ||
| ------------------------- | ||
|
|
||
| Do not suppress a warning from this rule. Indexers can't be exported so | ||
| they will be ignored by Godot, resulting in runtime errors. |
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.
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 think) But this is probably because the actual diagnostic.
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.
Yeah I just copied the diagnostic title, we could change it. I think I would use nested classes rather than subclasses here, what do you think? But I think it has to be plural because of the one or more.
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 just looked wrong to me, with some more thought, both versions are probably fine, but if we want to change it I would also go to a different wording like
contains nested classes that are derived from GodotObjectUh oh!
There was an error while loading. Please reload this page.
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 like that wording. This change needs to be done in the main repository as well, is there any other diagnostic that you think could be worded better? It'd be nice to make all the changes in a single PR while we're at it.
WIP: raulsntos/godot@79622bb
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.