]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Rework ReturnStatement.check to handle "current_return_type == null"
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 20 Feb 2020 13:19:10 +0000 (14:19 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Thu, 20 Feb 2020 13:19:10 +0000 (14:19 +0100)
Thanks to Daniel Espinosa Ortiz.

vala/valareturnstatement.vala

index 026dd1f2884ecc6700c83b0758fb6574e1a592ec..07eec37c290ec360359a88ee43fcb218b09f5d72 100644 (file)
@@ -83,16 +83,6 @@ public class Vala.ReturnStatement : CodeNode, Statement {
 
                checked = true;
 
-               if (return_expression != null) {
-                       return_expression.target_type = context.analyzer.current_return_type.copy ();
-               }
-
-               if (return_expression != null && !return_expression.check (context)) {
-                       // ignore inner error
-                       error = true;
-                       return false;
-               }
-
                if (context.analyzer.current_return_type == null) {
                        error = true;
                        Report.error (source_reference, "Return not allowed in this context");
@@ -112,6 +102,14 @@ public class Vala.ReturnStatement : CodeNode, Statement {
                        return false;
                }
 
+               return_expression.target_type = context.analyzer.current_return_type.copy ();
+
+               if (!return_expression.check (context)) {
+                       // ignore inner error
+                       error = true;
+                       return false;
+               }
+
                if (return_expression.value_type == null) {
                        error = true;
                        Report.error (source_reference, "Invalid expression in return value");