[vala/0.40] vala: Add local-variables to current scope regardless its error state



commit 79b32c5c5736ec388b7ca4fcfc3c3ce34e3b2aa8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sat Feb 22 16:00:22 2020 +0100

    vala: Add local-variables to current scope regardless its error state
    
    This avoids subsequent errors which are not useful to report when the user
    actually defined it.

 vala/valalocalvariable.vala | 17 +++++++++--------
 vala/valamemberaccess.vala  |  4 ++++
 2 files changed, 13 insertions(+), 8 deletions(-)
---
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index 3c946864f..6762c8ce1 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -83,11 +83,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;
                        }
                }
 
@@ -95,7 +92,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) {
@@ -105,10 +102,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 == null) {
                        /* var type */
 
@@ -207,8 +210,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
                var block = context.analyzer.current_symbol as Block;
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 695e05696..82c0ba71b 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -488,6 +488,10 @@ public class Vala.MemberAccess : Expression {
 
                        Report.error (source_reference, "The name `%s' does not exist in the context of 
`%s'".printf (member_name, base_type_name));
                        return false;
+               } else if (symbol_reference.error) {
+                       //ignore previous error
+                       error = true;
+                       return false;
                }
 
                var member = symbol_reference;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]