You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-15 13:51:40 +00:00
C# Add test suite for Diagnostic Analyzers: GlobalClass and MustBeVariant
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
using Godot;
|
||||
|
||||
// This works because it inherits from GodotObject.
|
||||
[GlobalClass]
|
||||
public partial class CustomGlobalClass1 : GodotObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// This works because it inherits from an object that inherits from GodotObject
|
||||
[GlobalClass]
|
||||
public partial class CustomGlobalClass2 : Node
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// This raises a GD0401 diagnostic error: global classes must inherit from GodotObject
|
||||
{|GD0401:[GlobalClass]
|
||||
public partial class CustomGlobalClass3
|
||||
{
|
||||
|
||||
}|}
|
||||
@@ -0,0 +1,15 @@
|
||||
using Godot;
|
||||
|
||||
// This works because it inherits from GodotObject and it doesn't have any generic type parameter.
|
||||
[GlobalClass]
|
||||
public partial class CustomGlobalClass : GodotObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// This raises a GD0402 diagnostic error: global classes can't have any generic type parameter
|
||||
{|GD0402:[GlobalClass]
|
||||
public partial class CustomGlobalClass<T> : GodotObject
|
||||
{
|
||||
|
||||
}|}
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
using Array = Godot.Collections.Array;
|
||||
|
||||
public class MustBeVariantGD0301
|
||||
{
|
||||
public void MethodCallsError()
|
||||
{
|
||||
// This raises a GD0301 diagnostic error: object is not Variant (and Method<T> requires a variant generic type).
|
||||
Method<{|GD0301:object|}>();
|
||||
}
|
||||
public void MethodCallsOk()
|
||||
{
|
||||
// All these calls are valid because they are Variant types.
|
||||
Method<bool>();
|
||||
Method<char>();
|
||||
Method<sbyte>();
|
||||
Method<byte>();
|
||||
Method<short>();
|
||||
Method<ushort>();
|
||||
Method<int>();
|
||||
Method<uint>();
|
||||
Method<long>();
|
||||
Method<ulong>();
|
||||
Method<float>();
|
||||
Method<double>();
|
||||
Method<string>();
|
||||
Method<Vector2>();
|
||||
Method<Vector2I>();
|
||||
Method<Rect2>();
|
||||
Method<Rect2I>();
|
||||
Method<Transform2D>();
|
||||
Method<Vector3>();
|
||||
Method<Vector3I>();
|
||||
Method<Vector4>();
|
||||
Method<Vector4I>();
|
||||
Method<Basis>();
|
||||
Method<Quaternion>();
|
||||
Method<Transform3D>();
|
||||
Method<Projection>();
|
||||
Method<Aabb>();
|
||||
Method<Color>();
|
||||
Method<Plane>();
|
||||
Method<Callable>();
|
||||
Method<Signal>();
|
||||
Method<GodotObject>();
|
||||
Method<StringName>();
|
||||
Method<NodePath>();
|
||||
Method<Rid>();
|
||||
Method<Dictionary>();
|
||||
Method<Array>();
|
||||
Method<byte[]>();
|
||||
Method<int[]>();
|
||||
Method<long[]>();
|
||||
Method<float[]>();
|
||||
Method<double[]>();
|
||||
Method<string[]>();
|
||||
Method<Vector2[]>();
|
||||
Method<Vector3[]>();
|
||||
Method<Color[]>();
|
||||
Method<GodotObject[]>();
|
||||
Method<StringName[]>();
|
||||
Method<NodePath[]>();
|
||||
Method<Rid[]>();
|
||||
}
|
||||
|
||||
public void Method<[MustBeVariant] T>()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Godot;
|
||||
|
||||
public class MustBeVariantGD0302
|
||||
{
|
||||
public void MethodOk<[MustBeVariant] T>()
|
||||
{
|
||||
// T is guaranteed to be a Variant-compatible type because it's annotated with the [MustBeVariant] attribute, so it can be used here.
|
||||
new ExampleClass<T>();
|
||||
Method<T>();
|
||||
}
|
||||
|
||||
public void MethodFail<T>()
|
||||
{
|
||||
// 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.
|
||||
new ExampleClass<{|GD0302:T|}>();
|
||||
Method<{|GD0302:T|}>();
|
||||
}
|
||||
|
||||
public void Method<[MustBeVariant] T>()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class ExampleClass<[MustBeVariant] T>
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user