]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Add local-variables to current scope regardless its error state
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 22 Feb 2020 15:00:22 +0000 (16:00 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 22 Feb 2020 15:01:32 +0000 (16:01 +0100)
This avoids subsequent errors which are not useful to report when the user
actually defined it.

vala/valalocalvariable.vala
vala/valamemberaccess.vala

index ec7b0da871f9b628769fd3b694f37e27cc82393e..2d6f7188bc7a4c62039cc5d1add633e3cc39d72c 100644 (file)
@@ -100,11 +100,8 @@ public class Vala.LocalVariable : Variable {
                        if (variable_type is VoidType) {
                                error = true;
                                Report.error (source_reference, "'void' not supported as variable type");
-                               return false;
-                       }
-                       if (!variable_type.check (context)) {
+                       } else if (!variable_type.check (context)) {
                                error = true;
-                               return false;
                        }
                        if (!external_package) {
                                context.analyzer.check_type (variable_type);
@@ -115,7 +112,7 @@ public class Vala.LocalVariable : Variable {
                bool is_initializer_list = false;
                int initializer_size = -1;
 
-               if (initializer != null) {
+               if (initializer != null && !error) {
                        initializer.target_type = variable_type;
 
                        if (initializer is InitializerList) {
@@ -125,10 +122,16 @@ public class Vala.LocalVariable : Variable {
 
                        if (!initializer.check (context)) {
                                error = true;
-                               return false;
                        }
                }
 
+               // local variables are defined even on errors
+               context.analyzer.current_symbol.scope.add (name, this);
+
+               if (error) {
+                       return false;
+               }
+
                if (variable_type is VarType) {
                        /* var type */
 
@@ -223,8 +226,6 @@ public class Vala.LocalVariable : Variable {
                        }
                }
 
-               context.analyzer.current_symbol.scope.add (name, this);
-
                // current_symbol is a Method if this is the `result'
                // variable used for postconditions
                unowned Block? block = context.analyzer.current_symbol as Block;
index a0dc84d62340703b0de82426b5fbf12ae1518c06..b8d5d12524c2607440d7470410e5b5168f85b8a4 100644 (file)
@@ -506,6 +506,10 @@ public class Vala.MemberAccess : Expression {
 
                        Report.error (source_reference, "The name `%s' does not exist in the context of `%s'%s".printf (member_name, base_type_name, base_type_package));
                        return false;
+               } else if (symbol_reference.error) {
+                       //ignore previous error
+                       error = true;
+                       return false;
                }
 
                unowned Symbol? member = symbol_reference;