GD0203.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. GD0203: The delegate signature of the signal must return void
  2. =============================================================
  3. ==================================== ======================================
  4. Value
  5. ==================================== ======================================
  6. **Rule ID** GD0203
  7. **Category** Usage
  8. **Fix is breaking or non-breaking** Breaking - If the return type is changed
  9. Non-breaking - If the ``[Signal]`` attribute is removed
  10. **Enabled by default** Yes
  11. ==================================== ======================================
  12. Cause
  13. -----
  14. A delegate annotated with the ``[Signal]`` attribute has a return type when
  15. ``void`` was expected.
  16. Rule description
  17. ----------------
  18. Every signal must return ``void``. There can be multiple callbacks registered
  19. for each signal, if signal callbacks could return something it wouldn't be
  20. possible to determine which of the returned values to use.
  21. .. code-block:: csharp
  22. // This signal delegate is invalid because it doesn't return void.
  23. public int InvalidSignalEventHandler();
  24. // This signal delegate is valid because it returns void.
  25. public void ValidSignalEventHandler();
  26. Take a look at the :ref:`C# signals <doc_c_sharp_signals>` documentation for more
  27. information about how to declare and use signals.
  28. How to fix violations
  29. ---------------------
  30. To fix a violation of this rule, change the delegate to return ``void`` or
  31. remove the ``[Signal]`` attribute from the delegate. Note that removing the
  32. attribute will mean the signal is not registered.
  33. .. tip::
  34. If the signal doesn't need to interact with Godot, consider using
  35. `C# events <https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/events/>`_
  36. directly. Pure C# events allow you to use any C# type for its parameters.
  37. When to suppress warnings
  38. -------------------------
  39. Do not suppress a warning from this rule. Signal delegates that return something
  40. will result in unexpected runtime errors.