From 94dfac8da7bf8230f292cad8839696f572e8357c Mon Sep 17 00:00:00 2001 From: "ocean (they/them)" Date: Wed, 15 Feb 2023 16:00:22 -0500 Subject: [PATCH] Add return type for GDScript getters --- modules/gdscript/gdscript_compiler.cpp | 2 +- .../scripts/analyzer/features/getter_return_type.gd | 9 +++++++++ .../scripts/analyzer/features/getter_return_type.out | 2 ++ 3 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/features/getter_return_type.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/getter_return_type.out diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp index 46cd4b0d55a..b34be111695 100644 --- a/modules/gdscript/gdscript_compiler.cpp +++ b/modules/gdscript/gdscript_compiler.cpp @@ -254,7 +254,7 @@ GDScriptCodeGenerator::Address GDScriptCompiler::_parse_expression(CodeGen &code if (codegen.script->member_indices.has(identifier)) { if (codegen.script->member_indices[identifier].getter != StringName() && codegen.script->member_indices[identifier].getter != codegen.function_name) { // Perform getter. - GDScriptCodeGenerator::Address temp = codegen.add_temporary(); + GDScriptCodeGenerator::Address temp = codegen.add_temporary(codegen.script->member_indices[identifier].data_type); Vector args; // No argument needed. gen->write_call_self(temp, codegen.script->member_indices[identifier].getter, args); return temp; diff --git a/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.gd b/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.gd new file mode 100644 index 00000000000..38bb7f6e9c2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.gd @@ -0,0 +1,9 @@ +var Value:int = 8 : + get: + return Value + set(v): + Value = v + +func test(): + var f:float = Value + print(int(f)) diff --git a/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.out b/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.out new file mode 100644 index 00000000000..b0cb63ef59d --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/getter_return_type.out @@ -0,0 +1,2 @@ +GDTEST_OK +8