From 9507f65e25fd02b1e5817b787afdbef334b964e7 Mon Sep 17 00:00:00 2001 From: Dmitrii Maganov Date: Wed, 28 Dec 2022 07:12:16 +0200 Subject: GDScript: Disallow return with value in void functions --- modules/gdscript/gdscript_analyzer.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'modules/gdscript/gdscript_analyzer.cpp') diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index fc2e6e94f3..05d19863ca 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2044,6 +2044,9 @@ void GDScriptAnalyzer::resolve_return(GDScriptParser::ReturnNode *p_return) { update_array_literal_element_type(expected_type, static_cast(p_return->return_value)); } } + if (has_expected_type && expected_type.is_hard_type() && expected_type.kind == GDScriptParser::DataType::BUILTIN && expected_type.builtin_type == Variant::NIL) { + push_error("A void function cannot return a value.", p_return); + } result = p_return->return_value->get_datatype(); } else { // Return type is null by default. -- cgit v1.2.3