MustBeVariant.GD0302.cs 682 B

123456789101112131415161718192021222324252627
  1. using Godot;
  2. public class MustBeVariantGD0302
  3. {
  4. public void MethodOk<[MustBeVariant] T>()
  5. {
  6. // T is guaranteed to be a Variant-compatible type because it's annotated with the [MustBeVariant] attribute, so it can be used here.
  7. new ExampleClass<T>();
  8. Method<T>();
  9. }
  10. public void MethodFail<T>()
  11. {
  12. // These two calls raise a GD0302 diagnostic error: T is not valid here because it may not a Variant type and method call and class require it.
  13. new ExampleClass<{|GD0302:T|}>();
  14. Method<{|GD0302:T|}>();
  15. }
  16. public void Method<[MustBeVariant] T>()
  17. {
  18. }
  19. }
  20. public class ExampleClass<[MustBeVariant] T>
  21. {
  22. }