From a1d06749f18c3f47c6443ece2ec625d8ee5f1761 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Thu, 22 Dec 2022 22:43:36 +0200 Subject: Unify typing of variables, constants and parameters in GDScript --- .../enum_class_var_init_with_wrong_enum_type.out | 2 +- .../enum_local_var_init_with_wrong_enum_type.out | 2 +- .../errors/setter_parameter_uses_property_type.out | 2 +- .../analyzer/features/default_arg_convertable.gd | 6 ++++ .../analyzer/features/default_arg_convertable.out | 2 ++ .../scripts/analyzer/features/null_initializer.gd | 32 ++++++++++++++++++++++ .../scripts/analyzer/features/null_initializer.out | 5 ++++ .../scripts/analyzer/features/weak_initializer.gd | 5 ++++ .../scripts/analyzer/features/weak_initializer.out | 3 ++ .../scripts/analyzer/typed_array_assignment.out | 2 +- 10 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/null_initializer.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/null_initializer.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/weak_initializer.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/weak_initializer.out (limited to 'modules/gdscript/tests/scripts') 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 b1710c798d..6fa2682d0a 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 -Value of type "MyOtherEnum (enum)" cannot be assigned to a variable of type "MyEnum (enum)". +Cannot assign a value of type MyOtherEnum (enum) to variable "class_var" with specified type MyEnum (enum). 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 b1710c798d..07fb19f1ff 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 -Value of type "MyOtherEnum (enum)" cannot be assigned to a variable of type "MyEnum (enum)". +Cannot assign a value of type MyOtherEnum (enum) to variable "local_var" with specified type MyEnum (enum). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/setter_parameter_uses_property_type.out b/modules/gdscript/tests/scripts/analyzer/errors/setter_parameter_uses_property_type.out index 9eb2a42ccd..2857cd53c8 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/setter_parameter_uses_property_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/setter_parameter_uses_property_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "int" cannot be assigned to a variable of type "String". +Cannot assign a value of type int to variable "x" with specified type String. diff --git a/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.gd b/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.gd new file mode 100644 index 0000000000..d0d04897e0 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.gd @@ -0,0 +1,6 @@ +func check(arg: float = 3): + return typeof(arg) == typeof(3.0) + +func test(): + if check(): + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.out b/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/default_arg_convertable.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/analyzer/features/null_initializer.gd b/modules/gdscript/tests/scripts/analyzer/features/null_initializer.gd new file mode 100644 index 0000000000..5a413e2015 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/null_initializer.gd @@ -0,0 +1,32 @@ +func check(input: int) -> bool: + return input == 1 + +var recur = null +var prop = null + +func check_arg(arg = null) -> void: + if arg != null: + print(check(arg)) + +func check_recur() -> void: + if recur != null: + print(check(recur)) + else: + recur = 1 + check_recur() + +func test() -> void: + check_arg(1) + + check_recur() + + if prop == null: + set('prop', 1) + print(check(prop)) + set('prop', null) + + var loop = null + while loop != 2: + if loop != null: + print(check(loop)) + loop = 1 if loop == null else 2 diff --git a/modules/gdscript/tests/scripts/analyzer/features/null_initializer.out b/modules/gdscript/tests/scripts/analyzer/features/null_initializer.out new file mode 100644 index 0000000000..f9783e4362 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/null_initializer.out @@ -0,0 +1,5 @@ +GDTEST_OK +true +true +true +true diff --git a/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.gd b/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.gd new file mode 100644 index 0000000000..c5f3ccc59e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.gd @@ -0,0 +1,5 @@ +func test(): + var bar = 1 + var foo: float = bar + print(typeof(foo)) + print(foo is float) diff --git a/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.out b/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.out new file mode 100644 index 0000000000..5d798c1f24 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/weak_initializer.out @@ -0,0 +1,3 @@ +GDTEST_OK +3 +true diff --git a/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out index 26b6e13d4f..ad2e6558d7 100644 --- a/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out +++ b/modules/gdscript/tests/scripts/analyzer/typed_array_assignment.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Assigned value for constant "arr" has type Array[String] which is not compatible with defined type Array[int]. +Cannot assign a value of type Array[String] to constant "arr" with specified type Array[int]. -- cgit v1.2.3