GD0402.rst 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. GD0402: The class must not be generic
  2. =====================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0402
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Breaking
  9. **Enabled by default** Yes
  10. ==================================== ======================================
  11. Cause
  12. -----
  13. A generic type is annotated with the ``[GlobalClass]`` attribute.
  14. Rule description
  15. ----------------
  16. The Godot editor assumes every :ref:`global class <doc_c_sharp_global_classes>`
  17. is instantiable, but generic types can't be instantiated because the type
  18. parameters are unbound.
  19. .. code-block:: csharp
  20. // This type is a valid global class because it's not generic.
  21. [GlobalClass]
  22. class SomeType : Node { }
  23. // This type is not a valid global class because it's generic.
  24. [GlobalClass]
  25. class SomeGenericType<T> { }
  26. How to fix violations
  27. ---------------------
  28. To fix a violation of this rule, change the type to remove the generic type parameters
  29. or remove the ``[GlobalClass]`` attribute.
  30. When to suppress warnings
  31. -------------------------
  32. Do not suppress a warning from this rule. Adding the ``[GlobalClass]`` to a
  33. generic type is an easy mistake to make and this warning helps users realize
  34. that it may result in unexpected errors.