diff options
Diffstat (limited to 'modules/gdscript/tests')
118 files changed, 1122 insertions, 175 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.gd b/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.gd new file mode 100644 index 0000000000..8123fc53d9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.gd @@ -0,0 +1,3 @@ +enum { V } +func test(): + V = 1 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assign_enum.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.gd b/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.gd new file mode 100644 index 0000000000..da2b13d690 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.gd @@ -0,0 +1,3 @@ +enum NamedEnum { V } +func test(): + NamedEnum.V = 1 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assign_named_enum.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.gd b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.gd new file mode 100644 index 0000000000..71616ea3af --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.gd @@ -0,0 +1,5 @@ +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } +enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2, OTHER_ENUM_VALUE_3 } + +func test(): + print(MyOtherEnum.OTHER_ENUM_VALUE_3 as MyEnum) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out new file mode 100644 index 0000000000..3a8d2a205a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Invalid cast. Enum "cast_enum_bad_enum.gd::MyEnum" does not have value corresponding to "MyOtherEnum.OTHER_ENUM_VALUE_3" (2). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.gd b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.gd new file mode 100644 index 0000000000..60a31fb318 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.gd @@ -0,0 +1,4 @@ +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } + +func test(): + print(2 as MyEnum) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out new file mode 100644 index 0000000000..bc0d8b7834 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Invalid cast. Enum "cast_enum_bad_int.gd::MyEnum" does not have enum value 2. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd new file mode 100644 index 0000000000..b8603dd4ca --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.gd @@ -0,0 +1,5 @@ +const array: Array = [0] + +func test(): + var key: int = 0 + array[key] = 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_array_index_assign.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd new file mode 100644 index 0000000000..9b5112b788 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.gd @@ -0,0 +1,5 @@ +const dictionary := {} + +func test(): + var key: int = 0 + dictionary[key] = 0 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out new file mode 100644 index 0000000000..5275183da2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_dictionary_index_assign.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a new value to a constant. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.gd new file mode 100644 index 0000000000..87fbe1229c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.gd @@ -0,0 +1,5 @@ +const base := [0] + +func test(): + var sub := base[0] + if sub is String: pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.out b/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.out new file mode 100644 index 0000000000..54c190cf8a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/constant_subscript_type.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Expression is of type "int" so it can't be of type "String". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.gd new file mode 100644 index 0000000000..2940c03515 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.gd @@ -0,0 +1,4 @@ +enum Enum {V1, V2} + +func test(): + Enum.clear() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.out new file mode 100644 index 0000000000..9ca86eca9c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_method.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call non-const Dictionary function "clear()" on enum "Enum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.gd new file mode 100644 index 0000000000..a66e2714d9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.gd @@ -0,0 +1,4 @@ +enum Enum {V1, V2} + +func test(): + var bad = Enum.V3 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.out new file mode 100644 index 0000000000..ddbdc17a42 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_bad_value.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot find member "V3" in base "enum_bad_value.gd::Enum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out index fde7e92f8c..02c4633586 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type "MyOtherEnum (enum)" to a target of type "MyEnum (enum)". +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out index 6fa2682d0a..441cccbf7b 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type MyOtherEnum (enum) to variable "class_var" with specified type MyEnum (enum). +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. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.gd new file mode 100644 index 0000000000..2c7dfafd06 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.gd @@ -0,0 +1,5 @@ +enum Enum {V1, V2} + +func test(): + var Enum2 = Enum + Enum2.clear() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.out new file mode 100644 index 0000000000..9ca86eca9c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_duplicate_bad_method.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot call non-const Dictionary function "clear()" on enum "Enum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.gd new file mode 100644 index 0000000000..62ac1c3108 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.gd @@ -0,0 +1,8 @@ +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } +enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 } + +func enum_func(e : MyEnum) -> void: + print(e) + +func test(): + enum_func(MyOtherEnum.OTHER_ENUM_VALUE_1) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out new file mode 100644 index 0000000000..e85f7d6f9f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out @@ -0,0 +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.gd new file mode 100644 index 0000000000..18b3ffb0fc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.gd @@ -0,0 +1,8 @@ +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } +enum MyOtherEnum { OTHER_ENUM_VALUE_1, OTHER_ENUM_VALUE_2 } + +func enum_func() -> MyEnum: + return MyOtherEnum.OTHER_ENUM_VALUE_1 + +func test(): + print(enum_func()) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out new file mode 100644 index 0000000000..f7ea3267fa --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out @@ -0,0 +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.gd new file mode 100644 index 0000000000..2b006f1f69 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.gd @@ -0,0 +1,10 @@ +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } + +class InnerClass: + enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } + +func test(): + var local_var: MyEnum = MyEnum.ENUM_VALUE_1 + print(local_var) + local_var = InnerClass.MyEnum.ENUM_VALUE_2 + print(local_var) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out new file mode 100644 index 0000000000..38df5a0cd8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out @@ -0,0 +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out index fde7e92f8c..2adcbd9edf 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type "MyOtherEnum (enum)" to a target of type "MyEnum (enum)". +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out index 07fb19f1ff..331113dd30 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type MyOtherEnum (enum) to variable "local_var" with specified type MyEnum (enum). +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. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.gd new file mode 100644 index 0000000000..744c2e47ce --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.gd @@ -0,0 +1,2 @@ +func test(): + var _bad = TileSet.TileShape.THIS_DOES_NOT_EXIST diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.out new file mode 100644 index 0000000000..49f041a2dd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_native_bad_value.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot find member "THIS_DOES_NOT_EXIST" in base "TileSet::TileShape". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.gd new file mode 100644 index 0000000000..81d5d59ae8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.gd @@ -0,0 +1,7 @@ +enum MyEnum { VALUE_A, VALUE_B, VALUE_C = 42 } + +func test(): + const P = preload("../features/enum_value_from_parent.gd") + var local_var: MyEnum + local_var = P.VALUE_B + print(local_var) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out new file mode 100644 index 0000000000..6298c026b4 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out @@ -0,0 +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.gd new file mode 100644 index 0000000000..96904c297a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.gd @@ -0,0 +1,8 @@ +class A: + enum { V } + +class B extends A: + enum { V } + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.out new file mode 100644 index 0000000000..7961a1a481 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_shadows_base_enum.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "V" already exists in parent class A. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.gd b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.gd new file mode 100644 index 0000000000..7e749db6b5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.gd @@ -0,0 +1,7 @@ +enum { ENUM_VALUE_1, ENUM_VALUE_2 } + +enum MyEnum { ENUM_VALUE_1, ENUM_VALUE_2 } + +func test(): + var local_var: MyEnum = ENUM_VALUE_1 + print(local_var) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out new file mode 100644 index 0000000000..b70121ed81 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out @@ -0,0 +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. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.gd b/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.gd new file mode 100644 index 0000000000..e1bed94406 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.gd @@ -0,0 +1,2 @@ +func test(): + TileSet.this_does_not_exist # Does not exist diff --git a/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.out b/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.out new file mode 100644 index 0000000000..06180c3a55 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/native_type_errors.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot find member "this_does_not_exist" in base "TileSet". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.gd new file mode 100644 index 0000000000..1cf3870a8e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.gd @@ -0,0 +1,8 @@ +class Outer: + const OUTER_CONST: = 0 + class Inner: + pass + +func test() -> void: + var type: = Outer.Inner + print(type.OUTER_CONST) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.out b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.out new file mode 100644 index 0000000000..73a54d7820 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> analyzer/errors/outer_class_constants.gd +>> 8 +>> Invalid get index 'OUTER_CONST' (on base: 'GDScript'). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.gd new file mode 100644 index 0000000000..c1074df915 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.gd @@ -0,0 +1,9 @@ +class Outer: + const OUTER_CONST: = 0 + class Inner: + pass + +func test() -> void: + var type: = Outer.Inner + var type_v: Variant = type + print(type_v.OUTER_CONST) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.out b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.out new file mode 100644 index 0000000000..92e7b9316e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_constants_as_variant.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> analyzer/errors/outer_class_constants_as_variant.gd +>> 9 +>> Invalid get index 'OUTER_CONST' (on base: 'GDScript'). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.gd new file mode 100644 index 0000000000..2631c3c500 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.gd @@ -0,0 +1,8 @@ +class Outer: + const OUTER_CONST: = 0 + class Inner: + pass + +func test() -> void: + var instance: = Outer.Inner.new() + print(instance.OUTER_CONST) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.out b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.out new file mode 100644 index 0000000000..892f8e2c3f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> analyzer/errors/outer_class_instance_constants.gd +>> 8 +>> Invalid get index 'OUTER_CONST' (on base: 'RefCounted (Inner)'). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.gd new file mode 100644 index 0000000000..cba788381e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.gd @@ -0,0 +1,9 @@ +class Outer: + const OUTER_CONST: = 0 + class Inner: + pass + +func test() -> void: + var instance: = Outer.Inner.new() + var instance_v: Variant = instance + print(instance_v.OUTER_CONST) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.out b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.out new file mode 100644 index 0000000000..8257e74f57 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_instance_constants_as_variant.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> analyzer/errors/outer_class_instance_constants_as_variant.gd +>> 9 +>> Invalid get index 'OUTER_CONST' (on base: 'RefCounted (Inner)'). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd index 65c0d9dabc..200c352223 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/outer_class_lookup.gd @@ -1,12 +1,12 @@ class A: - class B: - func test(): - print(A.B.D) + class B: + func test(): + print(A.B.D) class C: - class D: - pass + class D: + pass func test(): - var inst = A.B.new() - inst.test() + var inst = A.B.new() + inst.test() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.gd b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.gd new file mode 100644 index 0000000000..4e75ded96a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.gd @@ -0,0 +1,6 @@ +enum LocalNamed { VALUE_A, VALUE_B, VALUE_C = 42 } + +func test(): + const P = preload("../features/enum_from_outer.gd") + var x : LocalNamed + x = P.Named.VALUE_A diff --git a/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out new file mode 100644 index 0000000000..5e3c446bf6 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out @@ -0,0 +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". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/property_inline_set_type_error.out b/modules/gdscript/tests/scripts/analyzer/errors/property_inline_set_type_error.out index bbadf1ce27..bf776029b9 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/property_inline_set_type_error.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/property_inline_set_type_error.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type "String" to a target of type "int". +Value of type "String" cannot be assigned to a variable of type "int". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd index 63587942f7..393b66c9f0 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_null_in_void_func.gd @@ -1,2 +1,2 @@ func test() -> void: - return null + return null diff --git a/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd index 0ee4e7ea36..6be2730bab 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/return_variant_in_void_func.gd @@ -1,4 +1,4 @@ func test() -> void: - var a - a = 1 - return a + var a + a = 1 + return a diff --git a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd index 7881a0feb6..a94487d989 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/base_outer_resolution.gd @@ -11,4 +11,3 @@ func test() -> void: Extend.InnerClass.InnerInnerClass.test_a_b_c(A.new(), B.new(), C.new()) Extend.InnerClass.InnerInnerClass.test_enum(C.TestEnum.HELLO_WORLD) Extend.InnerClass.InnerInnerClass.test_a_prime(A.APrime.new()) - diff --git a/modules/gdscript/tests/scripts/analyzer/features/class_from_parent.gd b/modules/gdscript/tests/scripts/analyzer/features/class_from_parent.gd index 30e7deb05a..7c846c59bd 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/class_from_parent.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/class_from_parent.gd @@ -1,19 +1,19 @@ class A: - var x = 3 + var x = 3 class B: - var x = 4 + var x = 4 class C: - var x = 5 + var x = 5 class Test: - var a = A.new() - var b: B = B.new() - var c := C.new() + var a = A.new() + var b: B = B.new() + var c := C.new() func test(): - var test_instance := Test.new() - prints(test_instance.a.x) - prints(test_instance.b.x) - prints(test_instance.c.x) + var test_instance := Test.new() + prints(test_instance.a.x) + prints(test_instance.b.x) + prints(test_instance.c.x) diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.gd new file mode 100644 index 0000000000..9bc08f2dc5 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.gd @@ -0,0 +1,29 @@ +class_name EnumAccessOuterClass + +class InnerClass: + enum MyEnum { V0, V2, V1 } + + static func print_enums(): + print("Inner - Inner") + print(MyEnum.V0, MyEnum.V1, MyEnum.V2) + print(InnerClass.MyEnum.V0, InnerClass.MyEnum.V1, InnerClass.MyEnum.V2) + print(EnumAccessOuterClass.InnerClass.MyEnum.V0, EnumAccessOuterClass.InnerClass.MyEnum.V1, EnumAccessOuterClass.InnerClass.MyEnum.V2) + + print("Inner - Outer") + print(EnumAccessOuterClass.MyEnum.V0, EnumAccessOuterClass.MyEnum.V1, EnumAccessOuterClass.MyEnum.V2) + + +enum MyEnum { V0, V1, V2 } + +func print_enums(): + print("Outer - Outer") + print(MyEnum.V0, MyEnum.V1, MyEnum.V2) + print(EnumAccessOuterClass.MyEnum.V0, EnumAccessOuterClass.MyEnum.V1, EnumAccessOuterClass.MyEnum.V2) + + print("Outer - Inner") + print(InnerClass.MyEnum.V0, InnerClass.MyEnum.V1, InnerClass.MyEnum.V2) + print(EnumAccessOuterClass.InnerClass.MyEnum.V0, EnumAccessOuterClass.InnerClass.MyEnum.V1, EnumAccessOuterClass.InnerClass.MyEnum.V2) + +func test(): + print_enums() + InnerClass.print_enums() diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.out b/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.out new file mode 100644 index 0000000000..02e2e2b396 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_access_types.out @@ -0,0 +1,13 @@ +GDTEST_OK +Outer - Outer +012 +012 +Outer - Inner +021 +021 +Inner - Inner +021 +021 +021 +Inner - Outer +012 diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.gd new file mode 100644 index 0000000000..3076e7069f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.gd @@ -0,0 +1,13 @@ +enum Enum {V1, V2} + +func test(): + var enumAsDict : Dictionary = Enum.duplicate() + var enumAsVariant = Enum.duplicate() + print(Enum.has("V1")) + print(enumAsDict.has("V1")) + print(enumAsVariant.has("V1")) + enumAsDict.clear() + enumAsVariant.clear() + print(Enum.has("V1")) + print(enumAsDict.has("V1")) + print(enumAsVariant.has("V1")) diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.out b/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.out new file mode 100644 index 0000000000..a41924d0c9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_duplicate_into_dict.out @@ -0,0 +1,7 @@ +GDTEST_OK +true +true +true +true +false +false diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_from_base.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_from_base.gd new file mode 100644 index 0000000000..b3f9941903 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_from_base.gd @@ -0,0 +1,13 @@ +class A: + enum Named { VALUE_A, VALUE_B, VALUE_C = 42 } + +class B extends A: + var a = Named.VALUE_A + var b = Named.VALUE_B + var c = Named.VALUE_C + +func test(): + var test_instance = B.new() + prints("a", test_instance.a, test_instance.a == A.Named.VALUE_A) + prints("b", test_instance.b, test_instance.b == A.Named.VALUE_B) + prints("c", test_instance.c, test_instance.c == B.Named.VALUE_C) diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_from_parent.out b/modules/gdscript/tests/scripts/analyzer/features/enum_from_base.out index c160839da3..c160839da3 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/enum_from_parent.out +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_from_base.out diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_from_parent.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_from_outer.gd index 5f57c5b8c2..4d6852a9be 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/enum_from_parent.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_from_outer.gd @@ -1,5 +1,3 @@ -extends Node - enum Named { VALUE_A, VALUE_B, VALUE_C = 42 } class Test: diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_from_outer.out b/modules/gdscript/tests/scripts/analyzer/features/enum_from_outer.out new file mode 100644 index 0000000000..c160839da3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_from_outer.out @@ -0,0 +1,4 @@ +GDTEST_OK +a 0 true +b 1 true +c 42 true diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.gd new file mode 100644 index 0000000000..8a4e89d0d6 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.gd @@ -0,0 +1,112 @@ +class_name EnumFunctionTypecheckOuterClass + +enum MyEnum { V0, V1, V2 } + +class InnerClass: + enum MyEnum { V0, V2, V1 } + + func inner_inner_no_class(e : MyEnum) -> MyEnum: + print(e) + return e + + func inner_inner_class(e : InnerClass.MyEnum) -> InnerClass.MyEnum: + print(e) + return e + + func inner_inner_class_class(e : EnumFunctionTypecheckOuterClass.InnerClass.MyEnum) -> EnumFunctionTypecheckOuterClass.InnerClass.MyEnum: + print(e) + return e + + func inner_outer(e : EnumFunctionTypecheckOuterClass.MyEnum) -> EnumFunctionTypecheckOuterClass.MyEnum: + print(e) + return e + + func test(): + var _d + print("Inner") + + var o := EnumFunctionTypecheckOuterClass.new() + + _d = o.outer_outer_no_class(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + _d = o.outer_outer_class(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + _d = o.outer_inner_class(MyEnum.V1) + _d = o.outer_inner_class(InnerClass.MyEnum.V1) + _d = o.outer_inner_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = o.outer_inner_class_class(MyEnum.V1) + _d = o.outer_inner_class_class(InnerClass.MyEnum.V1) + _d = o.outer_inner_class_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + print() + + + _d = inner_inner_no_class(MyEnum.V1) + _d = inner_inner_no_class(InnerClass.MyEnum.V1) + _d = inner_inner_no_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = inner_inner_class(MyEnum.V1) + _d = inner_inner_class(InnerClass.MyEnum.V1) + _d = inner_inner_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = inner_inner_class_class(MyEnum.V1) + _d = inner_inner_class_class(InnerClass.MyEnum.V1) + _d = inner_inner_class_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = inner_outer(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + print() + + +func outer_outer_no_class(e : MyEnum) -> MyEnum: + print(e) + return e + +func outer_outer_class(e : EnumFunctionTypecheckOuterClass.MyEnum) -> EnumFunctionTypecheckOuterClass.MyEnum: + print(e) + return e + +func outer_inner_class(e : InnerClass.MyEnum) -> InnerClass.MyEnum: + print(e) + return e + +func outer_inner_class_class(e : EnumFunctionTypecheckOuterClass.InnerClass.MyEnum) -> EnumFunctionTypecheckOuterClass.InnerClass.MyEnum: + print(e) + return e + +func test(): + var _d + print("Outer") + + _d = outer_outer_no_class(MyEnum.V1) + _d = outer_outer_no_class(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + _d = outer_outer_class(MyEnum.V1) + _d = outer_outer_class(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + _d = outer_inner_class(InnerClass.MyEnum.V1) + _d = outer_inner_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = outer_inner_class_class(InnerClass.MyEnum.V1) + _d = outer_inner_class_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + print() + + var i := EnumFunctionTypecheckOuterClass.InnerClass.new() + + _d = i.inner_inner_no_class(InnerClass.MyEnum.V1) + _d = i.inner_inner_no_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = i.inner_inner_class(InnerClass.MyEnum.V1) + _d = i.inner_inner_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = i.inner_inner_class_class(InnerClass.MyEnum.V1) + _d = i.inner_inner_class_class(EnumFunctionTypecheckOuterClass.InnerClass.MyEnum.V1) + print() + _d = i.inner_outer(MyEnum.V1) + _d = i.inner_outer(EnumFunctionTypecheckOuterClass.MyEnum.V1) + print() + print() + + i.test() diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.out b/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.out new file mode 100644 index 0000000000..2e3ce1aa10 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_function_typecheck.out @@ -0,0 +1,55 @@ +GDTEST_OK +Outer +1 +1 + +1 +1 + +2 +2 + +2 +2 + + +2 +2 + +2 +2 + +2 +2 + +1 +1 + + +Inner +1 + +1 + +2 +2 +2 + +2 +2 +2 + + +2 +2 +2 + +2 +2 +2 + +2 +2 +2 + +1 diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.gd new file mode 100644 index 0000000000..b97d9bbb6b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.gd @@ -0,0 +1,16 @@ +const A := 1 +enum { B } +enum NamedEnum { C } + +class Parent: + const D := 2 + enum { E } + enum NamedEnum2 { F } + +class Child extends Parent: + enum TestEnum { A, B, C, D, E, F, Node, Object, Child, Parent} + +func test(): + print(A, B, NamedEnum.C, Parent.D, Parent.E, Parent.NamedEnum2.F) + print(Child.TestEnum.A, Child.TestEnum.B, Child.TestEnum.C, Child.TestEnum.D, Child.TestEnum.E, Child.TestEnum.F) + print(Child.TestEnum.Node, Child.TestEnum.Object, Child.TestEnum.Child, Child.TestEnum.Parent) diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.out b/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.out new file mode 100644 index 0000000000..864ba2a549 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_named_no_shadow.out @@ -0,0 +1,4 @@ +GDTEST_OK +100200 +012345 +6789 diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.gd new file mode 100644 index 0000000000..6a0a1e1969 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.gd @@ -0,0 +1,19 @@ +func print_enum(e : TileSet.TileShape) -> TileSet.TileShape: + print(e) + return e + +func test(): + var v : TileSet.TileShape + v = TileSet.TILE_SHAPE_SQUARE + v = print_enum(v) + v = print_enum(TileSet.TILE_SHAPE_SQUARE) + v = TileSet.TileShape.TILE_SHAPE_SQUARE + v = print_enum(v) + v = print_enum(TileSet.TileShape.TILE_SHAPE_SQUARE) + + v = TileSet.TILE_SHAPE_ISOMETRIC + v = print_enum(v) + v = print_enum(TileSet.TILE_SHAPE_ISOMETRIC) + v = TileSet.TileShape.TILE_SHAPE_ISOMETRIC + v = print_enum(v) + v = print_enum(TileSet.TileShape.TILE_SHAPE_ISOMETRIC) diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.out b/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.out new file mode 100644 index 0000000000..1126dcc6ec --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_native_access_types.out @@ -0,0 +1,9 @@ +GDTEST_OK +0 +0 +0 +0 +1 +1 +1 +1 diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd new file mode 100644 index 0000000000..b05ae82048 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd @@ -0,0 +1,86 @@ +class_name EnumTypecheckOuterClass + +enum MyEnum { V0, V1, V2 } + +class InnerClass: + enum MyEnum { V0, V2, V1 } + + static func test_inner_from_inner(): + print("Inner - Inner") + var e1 : MyEnum + var e2 : InnerClass.MyEnum + var e3 : EnumTypecheckOuterClass.InnerClass.MyEnum + + print("Self ", e1, e2, e3) + e1 = MyEnum.V1 + e2 = MyEnum.V1 + e3 = MyEnum.V1 + print("MyEnum ", e1, e2, e3) + e1 = InnerClass.MyEnum.V1 + e2 = InnerClass.MyEnum.V1 + e3 = InnerClass.MyEnum.V1 + print("Inner.MyEnum ", e1, e2, e3) + e1 = EnumTypecheckOuterClass.InnerClass.MyEnum.V1 + e2 = EnumTypecheckOuterClass.InnerClass.MyEnum.V1 + e3 = EnumTypecheckOuterClass.InnerClass.MyEnum.V1 + print("Outer.Inner.MyEnum ", e1, e2, e3) + + e1 = e2 + e1 = e3 + e2 = e1 + e2 = e3 + e3 = e1 + e3 = e2 + + print() + + static func test_outer_from_inner(): + print("Inner - Outer") + var e : EnumTypecheckOuterClass.MyEnum + + e = EnumTypecheckOuterClass.MyEnum.V1 + print("Outer.MyEnum ", e) + + print() + +func test_outer_from_outer(): + print("Outer - Outer") + var e1 : MyEnum + var e2 : EnumTypecheckOuterClass.MyEnum + + print("Self ", e1, e2) + e1 = MyEnum.V1 + e2 = MyEnum.V1 + print("Outer ", e1, e2) + e1 = EnumTypecheckOuterClass.MyEnum.V1 + e2 = EnumTypecheckOuterClass.MyEnum.V1 + print("Outer.MyEnum ", e1, e2) + + e1 = e2 + e2 = e1 + + print() + +func test_inner_from_outer(): + print("Outer - Inner") + var e1 : InnerClass.MyEnum + var e2 : EnumTypecheckOuterClass.InnerClass.MyEnum + + print("Inner ", e1, e2) + e1 = InnerClass.MyEnum.V1 + e2 = InnerClass.MyEnum.V1 + print("Outer.Inner ", e1, e2) + e1 = EnumTypecheckOuterClass.InnerClass.MyEnum.V1 + e2 = EnumTypecheckOuterClass.InnerClass.MyEnum.V1 + print("Outer.Inner.MyEnum ", e1, e2) + + e1 = e2 + e2 = e1 + + print() + +func test(): + test_outer_from_outer() + test_inner_from_outer() + InnerClass.test_outer_from_inner() + InnerClass.test_inner_from_inner() diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.out b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.out new file mode 100644 index 0000000000..3b2dcade26 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.out @@ -0,0 +1,19 @@ +GDTEST_OK +Outer - Outer +Self 00 +Outer 11 +Outer.MyEnum 11 + +Outer - Inner +Inner 00 +Outer.Inner 22 +Outer.Inner.MyEnum 22 + +Inner - Outer +Outer.MyEnum 1 + +Inner - Inner +Self 000 +MyEnum 222 +Inner.MyEnum 222 +Outer.Inner.MyEnum 222 diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd index 757744b6f1..0c740935b9 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant.gd @@ -2,5 +2,5 @@ const External = preload("external_enum_as_constant_external.notest.gd") const MyEnum = External.MyEnum func test(): - print(MyEnum.WAITING == 0) - print(MyEnum.GODOT == 1) + print(MyEnum.WAITING == 0) + print(MyEnum.GODOT == 1) diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd index 7c090844d0..24c1e41aab 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/external_enum_as_constant_external.notest.gd @@ -1,4 +1,4 @@ enum MyEnum { - WAITING, - GODOT + WAITING, + GODOT } diff --git a/modules/gdscript/tests/scripts/analyzer/features/lookup_class.gd b/modules/gdscript/tests/scripts/analyzer/features/lookup_class.gd new file mode 100644 index 0000000000..541da78332 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lookup_class.gd @@ -0,0 +1,50 @@ +# Inner-outer class lookup +class A: + const Q: = "right one" + +class X: + const Q: = "wrong one" + +class Y extends X: + class B extends A: + static func check() -> void: + print(Q) + +# External class lookup +const External: = preload("lookup_class_external.notest.gd") + +class Internal extends External.A: + static func check() -> void: + print(TARGET) + + class E extends External.E: + static func check() -> void: + print(TARGET) + print(WAITING) + +# Variable lookup +class C: + var Q := 'right one' + +class D: + const Q := 'wrong one' + +class E extends D: + class F extends C: + func check() -> void: + print(Q) + +# Test +func test() -> void: + # Inner-outer class lookup + Y.B.check() + print("---") + + # External class lookup + Internal.check() + Internal.E.check() + print("---") + + # Variable lookup + var f: = E.F.new() + f.check() diff --git a/modules/gdscript/tests/scripts/analyzer/features/lookup_class.out b/modules/gdscript/tests/scripts/analyzer/features/lookup_class.out new file mode 100644 index 0000000000..a0983c1438 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lookup_class.out @@ -0,0 +1,8 @@ +GDTEST_OK +right one +--- +wrong +right +godot +--- +right one diff --git a/modules/gdscript/tests/scripts/analyzer/features/lookup_class_external.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/lookup_class_external.notest.gd new file mode 100644 index 0000000000..a2904e20a8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lookup_class_external.notest.gd @@ -0,0 +1,15 @@ +class A: + const TARGET: = "wrong" + + class B: + const TARGET: = "wrong" + const WAITING: = "godot" + + class D extends C: + pass + +class C: + const TARGET: = "right" + +class E extends A.B.D: + pass diff --git a/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.gd b/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.gd new file mode 100644 index 0000000000..26cf6c7322 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.gd @@ -0,0 +1,41 @@ +signal hello + +func get_signal() -> Signal: + return hello + +class A: + signal hello + + func get_signal() -> Signal: + return hello + + class B: + signal hello + + func get_signal() -> Signal: + return hello + +class C extends A.B: + func get_signal() -> Signal: + return hello + +func test(): + var a: = A.new() + var b: = A.B.new() + var c: = C.new() + + var hello_a_result: = hello == a.get_signal() + var hello_b_result: = hello == b.get_signal() + var hello_c_result: = hello == c.get_signal() + var a_b_result: = a.get_signal() == b.get_signal() + var a_c_result: = a.get_signal() == c.get_signal() + var b_c_result: = b.get_signal() == c.get_signal() + var c_c_result: = c.get_signal() == c.get_signal() + + print("hello == A.hello? %s" % hello_a_result) + print("hello == A.B.hello? %s" % hello_b_result) + print("hello == C.hello? %s" % hello_c_result) + print("A.hello == A.B.hello? %s" % a_b_result) + print("A.hello == C.hello? %s" % a_c_result) + print("A.B.hello == C.hello? %s" % b_c_result) + print("C.hello == C.hello? %s" % c_c_result) diff --git a/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.out b/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.out new file mode 100644 index 0000000000..6b0d32eaf8 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/lookup_signal.out @@ -0,0 +1,8 @@ +GDTEST_OK +hello == A.hello? false +hello == A.B.hello? false +hello == C.hello? false +A.hello == A.B.hello? false +A.hello == C.hello? false +A.B.hello == C.hello? false +C.hello == C.hello? true diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd index c9caef7d7c..95f04421d1 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/return_variant_typed.gd @@ -1,5 +1,5 @@ func variant() -> Variant: - return 'variant' + return 'variant' func test(): - print(variant()) + print(variant()) diff --git a/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd new file mode 100644 index 0000000000..da24c06b2e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.gd @@ -0,0 +1,6 @@ +class Check extends Node: + func _set(_property: StringName, _value: Variant) -> bool: + return true + +func test() -> void: + print('OK') diff --git a/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out new file mode 100644 index 0000000000..1ccb591560 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/variant_arg_in_virtual_method.out @@ -0,0 +1,2 @@ +GDTEST_OK +OK diff --git a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd index ada6030132..179e454073 100644 --- a/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd +++ b/modules/gdscript/tests/scripts/parser/errors/class_name_after_annotation.gd @@ -3,4 +3,4 @@ class_name HelloWorld func test(): - pass + pass diff --git a/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd b/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd index 92dfb2366d..816783f239 100644 --- a/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd +++ b/modules/gdscript/tests/scripts/parser/errors/double_dictionary_comma.gd @@ -1,2 +1,2 @@ func test(): - var dictionary = { hello = "world",, } + var dictionary = { hello = "world",, } diff --git a/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd index 4608c778aa..7a745bd995 100644 --- a/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd +++ b/modules/gdscript/tests/scripts/parser/errors/match_multiple_variable_binds_in_branch.gd @@ -1,4 +1,4 @@ func test(): - match 1: - [[[var a]]], 2: - pass + match 1: + [[[var a]]], 2: + pass diff --git a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd index 43b513045b..a7197bf68f 100644 --- a/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd +++ b/modules/gdscript/tests/scripts/parser/features/advanced_expression_matching.gd @@ -1,34 +1,34 @@ func foo(x): - match x: - 1 + 1: - print("1+1") - [1,2,[1,{1:2,2:var z,..}]]: - print("[1,2,[1,{1:2,2:var z,..}]]") - print(z) - 1 if true else 2: - print("1 if true else 2") - 1 < 2: - print("1 < 2") - 1 or 2 and 1: - print("1 or 2 and 1") - 6 | 1: - print("1 | 1") - 1 >> 1: - print("1 >> 1") - 1, 2 or 3, 4: - print("1, 2 or 3, 4") - _: - print("wildcard") + match x: + 1 + 1: + print("1+1") + [1,2,[1,{1:2,2:var z,..}]]: + print("[1,2,[1,{1:2,2:var z,..}]]") + print(z) + 1 if true else 2: + print("1 if true else 2") + 1 < 2: + print("1 < 2") + 1 or 2 and 1: + print("1 or 2 and 1") + 6 | 1: + print("1 | 1") + 1 >> 1: + print("1 >> 1") + 1, 2 or 3, 4: + print("1, 2 or 3, 4") + _: + print("wildcard") func test(): - foo(6 | 1) - foo(1 >> 1) - foo(2) - foo(1) - foo(1+1) - foo(1 < 2) - foo([2, 1]) - foo(4) - foo([1, 2, [1, {1 : 2, 2:3}]]) - foo([1, 2, [1, {1 : 2, 2:[1,3,5, "123"], 4:2}]]) - foo([1, 2, [1, {1 : 2}]]) + foo(6 | 1) + foo(1 >> 1) + foo(2) + foo(1) + foo(1+1) + foo(1 < 2) + foo([2, 1]) + foo(4) + foo([1, 2, [1, {1 : 2, 2:3}]]) + foo([1, 2, [1, {1 : 2, 2:[1,3,5, "123"], 4:2}]]) + foo([1, 2, [1, {1 : 2}]]) diff --git a/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd b/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd index 2b46f1e88a..c959c6c6af 100644 --- a/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd +++ b/modules/gdscript/tests/scripts/parser/features/basic_expression_matching.gd @@ -1,27 +1,27 @@ func foo(x): - match x: - 1: - print("1") - 2: - print("2") - [1, 2]: - print("[1, 2]") - 3 or 4: - print("3 or 4") - 4: - print("4") - {1 : 2, 2 : 3}: - print("{1 : 2, 2 : 3}") - _: - print("wildcard") + match x: + 1: + print("1") + 2: + print("2") + [1, 2]: + print("[1, 2]") + 3 or 4: + print("3 or 4") + 4: + print("4") + {1 : 2, 2 : 3}: + print("{1 : 2, 2 : 3}") + _: + print("wildcard") func test(): - foo(0) - foo(1) - foo(2) - foo([1, 2]) - foo(3) - foo(4) - foo([4,4]) - foo({1 : 2, 2 : 3}) - foo({1 : 2, 4 : 3}) + foo(0) + foo(1) + foo(2) + foo([1, 2]) + foo(3) + foo(4) + foo([4,4]) + foo({1 : 2, 2 : 3}) + foo({1 : 2, 4 : 3}) diff --git a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd index c3b2506156..17d00bce3c 100644 --- a/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd +++ b/modules/gdscript/tests/scripts/parser/features/lambda_callable.gd @@ -1,4 +1,4 @@ func test(): - var my_lambda = func(x): - print(x) - my_lambda.call("hello") + var my_lambda = func(x): + print(x) + my_lambda.call("hello") diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd index 377dd25e9e..75857fb8ff 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd @@ -1,43 +1,43 @@ func foo(x): - match x: - {"key1": "value1", "key2": "value2"}: - print('{"key1": "value1", "key2": "value2"}') - {"key1": "value1", "key2"}: - print('{"key1": "value1", "key2"}') - {"key1", "key2": "value2"}: - print('{"key1", "key2": "value2"}') - {"key1", "key2"}: - print('{"key1", "key2"}') - {"key1": "value1"}: - print('{"key1": "value1"}') - {"key1"}: - print('{"key1"}') - _: - print("wildcard") + match x: + {"key1": "value1", "key2": "value2"}: + print('{"key1": "value1", "key2": "value2"}') + {"key1": "value1", "key2"}: + print('{"key1": "value1", "key2"}') + {"key1", "key2": "value2"}: + print('{"key1", "key2": "value2"}') + {"key1", "key2"}: + print('{"key1", "key2"}') + {"key1": "value1"}: + print('{"key1": "value1"}') + {"key1"}: + print('{"key1"}') + _: + print("wildcard") func bar(x): - match x: - {0}: - print("0") - {1}: - print("1") - {2}: - print("2") - _: - print("wildcard") + match x: + {0}: + print("0") + {1}: + print("1") + {2}: + print("2") + _: + print("wildcard") func test(): - foo({"key1": "value1", "key2": "value2"}) - foo({"key1": "value1", "key2": ""}) - foo({"key1": "", "key2": "value2"}) - foo({"key1": "", "key2": ""}) - foo({"key1": "value1"}) - foo({"key1": ""}) - foo({"key1": "value1", "key2": "value2", "key3": "value3"}) - foo({"key1": "value1", "key3": ""}) - foo({"key2": "value2"}) - foo({"key3": ""}) - bar({0: "0"}) - bar({1: "1"}) - bar({2: "2"}) - bar({3: "3"}) + foo({"key1": "value1", "key2": "value2"}) + foo({"key1": "value1", "key2": ""}) + foo({"key1": "", "key2": "value2"}) + foo({"key1": "", "key2": ""}) + foo({"key1": "value1"}) + foo({"key1": ""}) + foo({"key1": "value1", "key2": "value2", "key3": "value3"}) + foo({"key1": "value1", "key3": ""}) + foo({"key2": "value2"}) + foo({"key3": ""}) + bar({0: "0"}) + bar({1: "1"}) + bar({2: "2"}) + bar({3: "3"}) diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd index dbe223f5f5..a278ea1154 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_patterns_with_array.gd @@ -1,26 +1,26 @@ func foo(x): - match x: - 1, [2]: - print('1, [2]') - _: - print('wildcard') + match x: + 1, [2]: + print('1, [2]') + _: + print('wildcard') func bar(x): - match x: - [1], [2], [3]: - print('[1], [2], [3]') - [4]: - print('[4]') - _: - print('wildcard') + match x: + [1], [2], [3]: + print('[1], [2], [3]') + [4]: + print('[4]') + _: + print('wildcard') func test(): - foo(1) - foo([2]) - foo(2) - bar([1]) - bar([2]) - bar([3]) - bar([4]) - bar([5]) + foo(1) + foo([2]) + foo(2) + bar([1]) + bar([2]) + bar([3]) + bar([4]) + bar([5]) diff --git a/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd index a0ae7fb17c..0a71f33c25 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_multiple_variable_binds_in_pattern.gd @@ -1,6 +1,6 @@ func test(): - match [1, 2, 3]: - [var a, var b, var c]: - print(a == 1) - print(b == 2) - print(c == 3) + match [1, 2, 3]: + [var a, var b, var c]: + print(a == 1) + print(b == 2) + print(c == 3) diff --git a/modules/gdscript/tests/scripts/parser/features/multiline_assert.gd b/modules/gdscript/tests/scripts/parser/features/multiline_assert.gd new file mode 100644 index 0000000000..8c699c604d --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/multiline_assert.gd @@ -0,0 +1,24 @@ +func test(): + var x := 5 + + assert(x > 0) + assert(x > 0,) + assert(x > 0, 'message') + assert(x > 0, 'message',) + + assert( + x > 0 + ) + assert( + x > 0, + ) + assert( + x > 0, + 'message' + ) + assert( + x > 0, + 'message', + ) + + print('OK') diff --git a/modules/gdscript/tests/scripts/parser/features/multiline_assert.out b/modules/gdscript/tests/scripts/parser/features/multiline_assert.out new file mode 100644 index 0000000000..1ccb591560 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/multiline_assert.out @@ -0,0 +1,2 @@ +GDTEST_OK +OK diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd new file mode 100644 index 0000000000..4cbb464f59 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.gd @@ -0,0 +1,17 @@ +class A: + enum { X = 1 } + + class B: + enum { X = 2 } + +class C: + const X = 3 + + class D: + enum { X = 4 } + +func test(): + print(A.X) + print(A.B.X) + print(C.X) + print(C.D.X) diff --git a/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out new file mode 100644 index 0000000000..7536c38490 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/unnamed_enums_outer_conflicts.out @@ -0,0 +1,5 @@ +GDTEST_OK +1 +2 +3 +4 diff --git a/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd new file mode 100644 index 0000000000..a72ac9b5ee --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.gd @@ -0,0 +1,8 @@ +var weakling = 'not float' +func weak(x: float = weakling): + print(x) + print('typeof x is', typeof(x)) + +func test(): + print(typeof(weak())) + print('not ok') diff --git a/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out new file mode 100644 index 0000000000..8543cf976e --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/bad_conversion_for_default_parameter.out @@ -0,0 +1,8 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: weak() +>> runtime/errors/bad_conversion_for_default_parameter.gd +>> 2 +>> Trying to assign value of type 'String' to a variable of type 'float'. +0 +not ok diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd new file mode 100644 index 0000000000..a5ecaba38d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.gd @@ -0,0 +1,6 @@ +const array: Array = [{}] + +func test(): + var dictionary := array[0] + var key: int = 0 + dictionary[key] = 0 diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out new file mode 100644 index 0000000000..2a97eaea44 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/constant_array_is_deep.gd +>> 6 +>> Invalid set index '0' (on base: 'Dictionary') with value of type 'int' diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd new file mode 100644 index 0000000000..3e71cd0518 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.gd @@ -0,0 +1,4 @@ +const array: Array = [0] + +func test(): + array.push_back(0) diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out new file mode 100644 index 0000000000..ba3e1c46c6 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_push_back.out @@ -0,0 +1,7 @@ +GDTEST_RUNTIME_ERROR +>> ERROR +>> on function: push_back() +>> core/variant/array.cpp +>> 253 +>> Condition "_p->read_only" is true. +>> Array is in read-only state. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd new file mode 100644 index 0000000000..7b350e81ad --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.gd @@ -0,0 +1,4 @@ +const dictionary := {} + +func test(): + dictionary.erase(0) diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out new file mode 100644 index 0000000000..3e7ca11a4f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_erase.out @@ -0,0 +1,7 @@ +GDTEST_RUNTIME_ERROR +>> ERROR +>> on function: erase() +>> core/variant/dictionary.cpp +>> 177 +>> Condition "_p->read_only" is true. Returning: false +>> Dictionary is in read-only state. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd new file mode 100644 index 0000000000..4763210a7f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.gd @@ -0,0 +1,6 @@ +const dictionary := {0: [0]} + +func test(): + var array := dictionary[0] + var key: int = 0 + array[key] = 0 diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out new file mode 100644 index 0000000000..c807db6b0c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/constant_dictionary_is_deep.gd +>> 6 +>> Invalid set index '0' (on base: 'Array') with value of type 'int' diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd index 9b64084fa6..bd38259cec 100644 --- a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd +++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd @@ -9,7 +9,7 @@ func test(): array_sname.push_back(&"godot") print("String in Array: ", "godot" in array_sname) - # Not equal because the values are different types. + # Not equal because the values are different types. print("Arrays not equal: ", array_str != array_sname) var string_array: Array[String] = [] diff --git a/modules/gdscript/tests/scripts/runtime/features/await_on_void.gd b/modules/gdscript/tests/scripts/runtime/features/await_on_void.gd new file mode 100644 index 0000000000..46b9fbc951 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/await_on_void.gd @@ -0,0 +1,7 @@ +func wait() -> void: + pass + +func test(): + @warning_ignore(redundant_await) + await wait() + print("end") diff --git a/modules/gdscript/tests/scripts/runtime/features/await_on_void.out b/modules/gdscript/tests/scripts/runtime/features/await_on_void.out new file mode 100644 index 0000000000..5bc3dcf2db --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/await_on_void.out @@ -0,0 +1,2 @@ +GDTEST_OK +end diff --git a/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd new file mode 100644 index 0000000000..9d0c6317b3 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.gd @@ -0,0 +1,19 @@ +func literal(x: float = 1): + print('x is ', x) + print('typeof x is ', typeof(x)) + +var inferring := 2 +func inferred(x: float = inferring): + print('x is ', x) + print('typeof x is ', typeof(x)) + +var weakling = 3 +func weak(x: float = weakling): + print('x is ', x) + print('typeof x is ', typeof(x)) + +func test(): + literal() + inferred() + weak() + print('ok') diff --git a/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out new file mode 100644 index 0000000000..a9ef4919cf --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/conversion_for_default_parameter.out @@ -0,0 +1,8 @@ +GDTEST_OK +x is 1 +typeof x is 3 +x is 2 +typeof x is 3 +x is 3 +typeof x is 3 +ok diff --git a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd index 1f15026f17..94bac1974f 100644 --- a/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd +++ b/modules/gdscript/tests/scripts/runtime/features/dictionary_string_stringname_equivalent.gd @@ -13,5 +13,5 @@ func test(): print("String gets StringName: ", stringname_dict.get("abc")) stringname_dict[&"abc"] = 42 - # They compare equal because StringName keys are converted to String. + # They compare equal because StringName keys are converted to String. print("String Dictionary == StringName Dictionary: ", string_dict == stringname_dict) diff --git a/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd new file mode 100644 index 0000000000..1d4b400d81 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.gd @@ -0,0 +1,17 @@ +# https://github.com/godotengine/godot/issues/71177 + +func test(): + builtin_method() + builtin_method_static() + print("done") + +func builtin_method(): + var pba := PackedByteArray() + @warning_ignore(return_value_discarded) + pba.resize(1) # Built-in validated. + + +func builtin_method_static(): + var _pba := PackedByteArray() + @warning_ignore(return_value_discarded) + Vector2.from_angle(PI) # Static built-in validated. diff --git a/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out new file mode 100644 index 0000000000..8e68c97774 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/does_not_override_temp_values.out @@ -0,0 +1,2 @@ +GDTEST_OK +done diff --git a/modules/gdscript/tests/scripts/runtime/features/parameter_shadowing.gd b/modules/gdscript/tests/scripts/runtime/features/parameter_shadowing.gd index f33ba7dffd..252e100bda 100644 --- a/modules/gdscript/tests/scripts/runtime/features/parameter_shadowing.gd +++ b/modules/gdscript/tests/scripts/runtime/features/parameter_shadowing.gd @@ -3,23 +3,23 @@ var a: int = 1 func shadow_regular_assignment(a: Variant, b: Variant) -> void: - print(a) - print(self.a) - a = b - print(a) - print(self.a) + print(a) + print(self.a) + a = b + print(a) + print(self.a) var v := Vector2(0.0, 0.0) func shadow_subscript_assignment(v: Vector2, x: float) -> void: - print(v) - print(self.v) - v.x += x - print(v) - print(self.v) + print(v) + print(self.v) + v.x += x + print(v) + print(self.v) func test(): - shadow_regular_assignment('a', 'b') - shadow_subscript_assignment(Vector2(1.0, 1.0), 5.0) + shadow_regular_assignment('a', 'b') + shadow_subscript_assignment(Vector2(1.0, 1.0), 5.0) diff --git a/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd new file mode 100644 index 0000000000..cc34e71b01 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.gd @@ -0,0 +1,45 @@ +# https://github.com/godotengine/godot/issues/70964 + +func test(): + test_construct(0, false) + test_utility(0, false) + test_builtin_call(Vector2.UP, false) + test_builtin_call_validated(Vector2.UP, false) + test_object_call(RefCounted.new(), false) + test_object_call_method_bind(Resource.new(), false) + test_object_call_ptrcall(RefCounted.new(), false) + + print("end") + +func test_construct(v, f): + Vector2(v, v) # Built-in type construct. + assert(not f) # Test unary operator reading from `nil`. + +func test_utility(v, f): + abs(v) # Utility function. + assert(not f) # Test unary operator reading from `nil`. + +func test_builtin_call(v, f): + @warning_ignore(unsafe_method_access) + v.angle() # Built-in method call. + assert(not f) # Test unary operator reading from `nil`. + +func test_builtin_call_validated(v: Vector2, f): + @warning_ignore(return_value_discarded) + v.abs() # Built-in method call validated. + assert(not f) # Test unary operator reading from `nil`. + +func test_object_call(v, f): + @warning_ignore(unsafe_method_access) + v.get_reference_count() # Native type method call. + assert(not f) # Test unary operator reading from `nil`. + +func test_object_call_method_bind(v: Resource, f): + @warning_ignore(return_value_discarded) + v.duplicate() # Native type method call with MethodBind. + assert(not f) # Test unary operator reading from `nil`. + +func test_object_call_ptrcall(v: RefCounted, f): + @warning_ignore(return_value_discarded) + v.get_reference_count() # Native type method call with ptrcall. + assert(not f) # Test unary operator reading from `nil`. diff --git a/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.out b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.out new file mode 100644 index 0000000000..5bc3dcf2db --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/standalone-calls-do-not-write-to-nil.out @@ -0,0 +1,2 @@ +GDTEST_OK +end diff --git a/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.gd b/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.gd new file mode 100644 index 0000000000..af3f3cb941 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.gd @@ -0,0 +1,9 @@ +# https://github.com/godotengine/godot/issues/71172 + +func test(): + @warning_ignore(narrowing_conversion) + var foo: int = 0.0 + print(typeof(foo) == TYPE_INT) + var dict : Dictionary = {"a":0.0} + foo = dict.get("a") + print(typeof(foo) == TYPE_INT) diff --git a/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.out b/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.out new file mode 100644 index 0000000000..9d111a8322 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/use_conversion_assign_with_variant_value.out @@ -0,0 +1,3 @@ +GDTEST_OK +true +true |