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

Multiple C# classes hiding inherited members in GodotSharp #15763

Closed
redxdev opened this issue Jan 15, 2018 · 11 comments
Closed

Multiple C# classes hiding inherited members in GodotSharp #15763

redxdev opened this issue Jan 15, 2018 · 11 comments

Comments

@redxdev
Copy link

redxdev commented Jan 15, 2018

Godot version:
3.0 14b230f

OS/device including version:
Windows 10 1709

Issue description:
When the GodotSharp solution is built for the first time, a number of warnings appear as some generated method names either hide C# object members or other Godot-specific members.

screenshot

Full list of members:

  • ARVRPositionalTracker.GetType() hides object.GetType()
  • LightOccluder2D.LightMask hides CanvasItem.LightMask
  • LineEdit.FocusMode hides Control.FocusMode
  • Slider.FocusMode hides Control.FocusMode
  • PathFollow2D.Rotate hides Node2D.Rotate(float)
  • ArrayMesh.BlendShapeMode hides Mesh.BlendShapeMode
  • ArrayMesh.ArrayFormat hides Mesh.ArrayFormat
  • ArrayMesh.ArrayType hides Mesh.ArrayType

Method hiding may result in unexpected behavior in C# scripts.

It actually seems that some of the members listed above actually reimplement the members they are hiding without any changes and as such work as expected, but they still emit a warning.

@neikeq
Copy link
Contributor

neikeq commented Jan 16, 2018

Should use new to get rid of the warnings:

// TODO: there are constants that hide inherited members. must explicitly use `new` to avoid warnings
// e.g.: warning CS0108: 'SpriteBase3D.FLAG_MAX' hides inherited member 'GeometryInstance.FLAG_MAX'. Use the new keyword if hiding was intended.

These are fine, as long as they are actual members hiding inherited members in the Godot API, and not the result of renaming them to PascalCase that is causing it.

BTW, why do the messages in the screenshot have an error icon instead of warning?

@redxdev
Copy link
Author

redxdev commented Jan 16, 2018

BTW, why do the messages in the screenshot have an error icon instead of warning?

Good question. I found this issue a while back and it was showing the warning icon but recently it changed to an error icon. I'll do some digging and figure out which commit it was that broke it and submit a separate issue.

These are fine, as long as they are actual members hiding inherited members in the Godot API, and not the result of renaming them to PascalCase that is causing it.

The ARVRPositionalTracker.GetType() method definitely needs to be changed, though, as it hides object.GetType() (that's System.Object, not Godot.Object) which is used for C# reflection. Using new would be a bad idea for that method.

@redxdev
Copy link
Author

redxdev commented Jan 16, 2018

Made a separate issue for warnings appearing as errors #15768

@akien-mga
Copy link
Member

Is this still relevant in the current master branch?

@aaronfranke
Copy link
Member

Still relevant in master. Updated list of warnings:

  • Object.ToString() hides object.ToString()
  • CPUParticles.Flags hides GeometryInstance.Flags
  • ARVRPositionalTracker.GetType() hides object.GetType()
  • ArrayMesh.BlendShapeMode hides Mesh.BlendShapeMode
  • ArrayMesh.ArrayFormat hides Mesh.ArrayFormat
  • ArrayMesh.ArrayType hides Mesh.ArrayType
  • PathFollow2D.Rotate hides Node2D.Rotate
  • LightOccluder2D.LightMask hides CanvasItem.LightMask
  • LineEdit.FocusMode hides Control.FocusMode
  • Slider.FocusMode hides Control.FocusMode

@aaronfranke
Copy link
Member

aaronfranke commented Dec 25, 2019

Most of these things can be renamed in core and would improve the consistency and/or readability of the API. See also: #16863. Here's a few proposals:

  • LightOccluder2D has light_mask but it also has get_occluder_light_mask and set_occluder_light_mask, so this property would make more sense if it was called occluder_light_mask.

  • CPUParticles has a Flags enum, but it also has get_particle_flag and set_particle_flag, so this enum would make more sense if it was called ParticleFlags.

  • ARVRPositionalTracker has get_type, but it also has get_tracker_id, and get_type is super ambiguous, so it would make more sense if this was called get_tracker_type. I also noticed it has a method called get_name which also seems ambiguous, so how about get_tracker_name?

  • PathFollow2D has rotate, which throws a warning due to Node2D's rotate(), and I don't think it's ideal to give a property and method the same name. Not 100% sure what to rename it to, so I mentioned it here: Naming of boolean setters/getters #33026 (comment)

For the Mesh/ArrayMesh ones, the current code is really confusing:

  • Mesh.BlendShapeMode is only used in ArrayMesh AFAICT, so why not move it there?

  • ArrayMesh.ArrayType is literally the exact same as Mesh.ArrayType, why does it exist?

  • ArrayMesh.ArrayFormat is a subset of Mesh.ArrayFormat, and it's a bitwise enum, so we could just use Mesh.ArrayFormat and ignore the higher order bits, but I guess it makes sense as-is.

I have a branch here which solves all of these problems. I don't think the first three require much discussion, they seem like very good improvements. For PathFollow2D, I renamed the bool to rotates for now, but I think this one requires some discussion. For ArrayMesh, I removed ArrayType and moved Mesh.BlendShapeMode to it, discussion would be nice. I'll submit a pull request after 3.2 is released.

For the remaining warnings, I'm not getting a warning about LineEdit.FocusMode and Slider.FocusMode anymore, and I'm getting a few warnings about editor code:

  ObjectType/ResourceFormatLoader.cs(12,52): warning CS1574: XML comment has cref attribute 'EditorImportPlugin' that could not be resolved [/home/franke/workspace/godot/modules/mono/glue/Managed/Generated/GodotSharp/GodotSharp.csproj]
  ObjectType/Spatial.cs(168,102): warning CS1574: XML comment has cref attribute 'EditorSpatialGizmo' that could not be resolved [/home/franke/workspace/godot/modules/mono/glue/Managed/Generated/GodotSharp/GodotSharp.csproj]
  ObjectType/EditorSpatialGizmoPlugin.cs(73,31): warning CS0108: 'EditorSpatialGizmoPlugin.GetName()' hides inherited member 'Resource.GetName()'. Use the new keyword if hiding was intended. [/home/franke/workspace/godot/modules/mono/glue/Managed/Generated/GodotSharpEditor/GodotSharpEditor.csproj]

@vnen
Copy link
Member

vnen commented Jan 7, 2020

  • LightOccluder2D has light_mask but it also has get_occluder_light_mask and set_occluder_light_mask, so this property would make more sense if it was called occluder_light_mask

It's already the occluder, no need to have it on the name of class in the property. But honestly, if CanvasItem already has a light mask property, why does LightOccluder2D have a different one? I believe we can remove the specific property and just use the CanvasItem one.

@akien-mga
Copy link
Member

This needs to be handled ASAP if we want to handle it at all - if we don't we should silence the warnings in msbuild as they're quite noisy. But I think fixing the warnings would be best.

Here's the current log from building assemblies in the master branch with .NET 6:
dotnet_assemblies_build.log

@neikeq
Copy link
Contributor

neikeq commented Sep 8, 2022

A lot of new classes (GDExtension-related mostly) are making this worse. I'm considering ignoring them in the bindings.

@Anutrix
Copy link
Contributor

Anutrix commented Feb 14, 2023

There seems to be some new entries in the warning list.
This is seen in one of my MR's pipeline:
image

@YuriSizov YuriSizov modified the milestones: 4.0, 4.1 Feb 24, 2023
@YuriSizov YuriSizov modified the milestones: 4.1, 4.x Jun 22, 2023
@raulsntos
Copy link
Member

@raulsntos raulsntos modified the milestones: 4.x, 4.3 May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

8 participants