GDScript: Fix constant conversions

This commit is contained in:
Dmitrii Maganov
2023-01-22 10:32:05 +02:00
parent 218bef90af
commit 31e0ae2012
29 changed files with 204 additions and 105 deletions

View File

@@ -0,0 +1,3 @@
func test():
var var_color: String = Color.RED
print('not ok')

View File

@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type "Color" as "String".

View File

@@ -1,2 +0,0 @@
GDTEST_ANALYZER_ERROR
Invalid cast. Enum "cast_enum_bad_enum.gd::MyEnum" does not have value corresponding to "MyOtherEnum.OTHER_ENUM_VALUE_3" (2).

View File

@@ -1,2 +0,0 @@
GDTEST_ANALYZER_ERROR
Invalid cast. Enum "cast_enum_bad_int.gd::MyEnum" does not have enum value 2.

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Value of type "enum_class_var_assign_with_wrong_enum_type.gd::MyOtherEnum" cannot be assigned to a variable of type "enum_class_var_assign_with_wrong_enum_type.gd::MyEnum".
Cannot assign a value of type "enum_class_var_assign_with_wrong_enum_type.gd::MyOtherEnum" as "enum_class_var_assign_with_wrong_enum_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type enum_class_var_init_with_wrong_enum_type.gd::MyOtherEnum to variable "class_var" with specified type enum_class_var_init_with_wrong_enum_type.gd::MyEnum.
Cannot assign a value of type "enum_class_var_init_with_wrong_enum_type.gd::MyOtherEnum" as "enum_class_var_init_with_wrong_enum_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid argument for "enum_func()" function: argument 1 should be "enum_function_parameter_wrong_type.gd::MyEnum" but is "enum_function_parameter_wrong_type.gd::MyOtherEnum".
Cannot pass a value of type "enum_function_parameter_wrong_type.gd::MyOtherEnum" as "enum_function_parameter_wrong_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot return value of type "enum_function_return_wrong_type.gd::MyOtherEnum" because the function return type is "enum_function_return_wrong_type.gd::MyEnum".
Cannot return a value of type "enum_function_return_wrong_type.gd::MyOtherEnum" as "enum_function_return_wrong_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Value of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::InnerClass::MyEnum" cannot be assigned to a variable of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::MyEnum".
Cannot assign a value of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::InnerClass::MyEnum" as "enum_local_var_assign_outer_with_wrong_enum_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Value of type "enum_local_var_assign_with_wrong_enum_type.gd::MyOtherEnum" cannot be assigned to a variable of type "enum_local_var_assign_with_wrong_enum_type.gd::MyEnum".
Cannot assign a value of type "enum_local_var_assign_with_wrong_enum_type.gd::MyOtherEnum" as "enum_local_var_assign_with_wrong_enum_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type enum_local_var_init_with_wrong_enum_type.gd::MyOtherEnum to variable "local_var" with specified type enum_local_var_init_with_wrong_enum_type.gd::MyEnum.
Cannot assign a value of type "enum_local_var_init_with_wrong_enum_type.gd::MyOtherEnum" as "enum_local_var_init_with_wrong_enum_type.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Value of type "enum_value_from_parent.gd::<anonymous enum>" cannot be assigned to a variable of type "enum_preload_unnamed_assign_to_named.gd::MyEnum".
Cannot assign a value of type "enum_value_from_parent.gd::<anonymous enum>" as "enum_preload_unnamed_assign_to_named.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a value of type enum_unnamed_assign_to_named.gd::<anonymous enum> to variable "local_var" with specified type enum_unnamed_assign_to_named.gd::MyEnum.
Cannot assign a value of type "enum_unnamed_assign_to_named.gd::<anonymous enum>" as "enum_unnamed_assign_to_named.gd::MyEnum".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot return value of type "String" because the function return type is "int".
Cannot return a value of type "String" as "int".

View File

@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
Value of type "enum_from_outer.gd::Named" cannot be assigned to a variable of type "preload_enum_error.gd::LocalNamed".
Cannot assign a value of type "enum_from_outer.gd::Named" as "preload_enum_error.gd::LocalNamed".

View File

@@ -0,0 +1,16 @@
const const_color: Color = 'red'
func func_color(arg_color: Color = 'blue') -> bool:
return arg_color == Color.BLUE
@warning_ignore("assert_always_true")
func test():
assert(const_color == Color.RED)
assert(func_color() == true)
assert(func_color('blue') == true)
var var_color: Color = 'green'
assert(var_color == Color.GREEN)
print('ok')

View File

@@ -0,0 +1,2 @@
GDTEST_OK
ok

View File

@@ -0,0 +1,24 @@
const const_float_int: float = 19
const const_float_plus: float = 12 + 22
const const_float_cast: float = 76 as float
const const_packed_empty: PackedFloat64Array = []
const const_packed_ints: PackedFloat64Array = [52]
@warning_ignore("assert_always_true")
func test():
assert(typeof(const_float_int) == TYPE_FLOAT)
assert(str(const_float_int) == '19')
assert(typeof(const_float_plus) == TYPE_FLOAT)
assert(str(const_float_plus) == '34')
assert(typeof(const_float_cast) == TYPE_FLOAT)
assert(str(const_float_cast) == '76')
assert(typeof(const_packed_empty) == TYPE_PACKED_FLOAT64_ARRAY)
assert(str(const_packed_empty) == '[]')
assert(typeof(const_packed_ints) == TYPE_PACKED_FLOAT64_ARRAY)
assert(str(const_packed_ints) == '[52]')
assert(typeof(const_packed_ints[0]) == TYPE_FLOAT)
assert(str(const_packed_ints[0]) == '52')
print('ok')

View File

@@ -0,0 +1,2 @@
GDTEST_OK
ok

View File

@@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> INT_AS_ENUM_WITHOUT_MATCH
>> Cannot cast 2 as Enum "cast_enum_bad_enum.gd::MyEnum": no enum member has matching value.
2

View File

@@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> INT_AS_ENUM_WITHOUT_MATCH
>> Cannot cast 2 as Enum "cast_enum_bad_int.gd::MyEnum": no enum member has matching value.
2

View File

@@ -1,19 +1,19 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> INT_ASSIGNED_TO_ENUM
>> INT_AS_ENUM_WITHOUT_CAST
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
>> WARNING
>> Line: 9
>> INT_ASSIGNED_TO_ENUM
>> INT_AS_ENUM_WITHOUT_CAST
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
>> WARNING
>> Line: 12
>> INT_ASSIGNED_TO_ENUM
>> INT_AS_ENUM_WITHOUT_CAST
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
>> WARNING
>> Line: 14
>> INT_ASSIGNED_TO_ENUM
>> INT_AS_ENUM_WITHOUT_CAST
>> Integer used when an enum value is expected. If this is intended cast the integer to the enum type.
0
1