From 4bdba718c5fcb2bd58827b8ede3ea7d0c4251fbd Mon Sep 17 00:00:00 2001 From: George Marques Date: Tue, 9 Apr 2024 15:49:44 -0300 Subject: GDScript: Infer type with string format operator If the left value type is known to be String, assume the format operator (`%`) will return a string, since it works with any type in the right hand side. This is also used by type inference even if the right hand type is unknown at compile time. --- .../tests/scripts/analyzer/features/infer_type_on_string_format.gd | 6 ++++++ .../tests/scripts/analyzer/features/infer_type_on_string_format.out | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out (limited to 'modules/gdscript/tests/scripts') diff --git a/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd new file mode 100644 index 0000000000..c83a3a8a14 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd @@ -0,0 +1,6 @@ +# GH-88082 + +func test(): + var x = 1 + var message := "value: %s" % x + print(message) diff --git a/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out new file mode 100644 index 0000000000..cf6464a4c3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out @@ -0,0 +1,2 @@ +GDTEST_OK +value: 1 -- cgit v1.2.3