[vala/wip/issue/911: 4/4] WIP vala: Improve dealing with errornous nodes



commit 070c81c6551388caadeaf63622d058ebdba70c5c
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Feb 20 14:19:10 2020 +0100

    WIP vala: Improve dealing with errornous nodes
    
    See https://gitlab.gnome.org/GNOME/vala/issues/911

 vala/valaconstant.vala         |  4 ++--
 vala/valaconstructor.vala      | 12 +++++++-----
 vala/valaflowanalyzer.vala     |  2 +-
 vala/valalocalvariable.vala    |  5 ++++-
 vala/valamemberaccess.vala     |  5 +++++
 vala/valamethodcall.vala       | 10 ++++++++--
 vala/valapropertyaccessor.vala |  2 ++
 vala/valareturnstatement.vala  |  1 +
 8 files changed, 30 insertions(+), 11 deletions(-)
---
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index 809cb883d..b0beddc2b 100644
--- a/vala/valaconstant.vala
+++ b/vala/valaconstant.vala
@@ -190,8 +190,8 @@ public class Vala.Constant : Symbol {
                } else if (type is ArrayType) {
                        unowned ArrayType array_type = (ArrayType) type;
                        return check_const_type (array_type.element_type, context);
-               } else if (type.type_symbol.is_subtype_of (context.analyzer.string_type.type_symbol)) {
-                       return true;
+               } else if (type.type_symbol != null) {
+                       return type.type_symbol.is_subtype_of (context.analyzer.string_type.type_symbol);
                } else {
                        return false;
                }
diff --git a/vala/valaconstructor.vala b/vala/valaconstructor.vala
index a4844c728..a867f3a39 100644
--- a/vala/valaconstructor.vala
+++ b/vala/valaconstructor.vala
@@ -77,11 +77,13 @@ public class Vala.Constructor : Subroutine {
                        body.check (context);
                }
 
-               var body_errors = new ArrayList<DataType> ();
-               body.get_error_types (body_errors);
-               foreach (DataType body_error_type in body_errors) {
-                       if (!((ErrorType) body_error_type).dynamic_error) {
-                               Report.warning (body_error_type.source_reference, "unhandled error 
`%s'".printf (body_error_type.to_string()));
+               if (body != null && !body.error) {
+                       var body_errors = new ArrayList<DataType> ();
+                       body.get_error_types (body_errors);
+                       foreach (DataType body_error_type in body_errors) {
+                               if (!((ErrorType) body_error_type).dynamic_error) {
+                                       Report.warning (body_error_type.source_reference, "unhandled error 
`%s'".printf (body_error_type.to_string()));
+                               }
                        }
                }
 
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 978ab94f8..03aae237f 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -987,7 +987,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                        var error_block = new BasicBlock ();
                        all_basic_blocks.add (error_block);
 
-                       if (catch_clause.error_type != null) {
+                       if (catch_clause.error_type != null && !catch_clause.error) {
                                if (context.profile == Profile.GOBJECT) {
                                        unowned ErrorType error_type = (ErrorType) catch_clause.error_type;
                                        jump_stack.add (new JumpTarget.error_target (error_block, 
catch_clause, catch_clause.error_type.type_symbol as ErrorDomain, error_type.error_code, null));
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index a6a1a8842..ec7b0da87 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -102,7 +102,10 @@ public class Vala.LocalVariable : Variable {
                                Report.error (source_reference, "'void' not supported as variable type");
                                return false;
                        }
-                       variable_type.check (context);
+                       if (!variable_type.check (context)) {
+                               error = true;
+                               return false;
+                       }
                        if (!external_package) {
                                context.analyzer.check_type (variable_type);
                        }
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 946bd2b0a..a0dc84d62 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -307,6 +307,10 @@ public class Vala.MemberAccess : Expression {
 
                        if (symbol_reference == null && source_reference != null) {
                                foreach (UsingDirective ns in source_reference.using_directives) {
+                                       if (ns.error) {
+                                               // ignore previous error
+                                               continue;
+                                       }
                                        var local_sym = ns.namespace_symbol.scope.lookup (member_name);
                                        if (local_sym != null) {
                                                if (symbol_reference != null && symbol_reference != 
local_sym) {
@@ -825,6 +829,7 @@ public class Vala.MemberAccess : Expression {
                        } else if (symbol_reference is Property) {
                                value_type = new PropertyPrototype ((Property) symbol_reference);
                        } else {
+                               error = true;
                                value_type = new InvalidType ();
                        }
 
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 4a15a6cb4..c79334763 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -466,6 +466,7 @@ public class Vala.MethodCall : Expression {
                        if (format_literal != null) {
                                string format = format_literal.eval ();
                                if (!context.analyzer.check_print_format (format, arg_it, source_reference)) {
+                                       error = true;
                                        return false;
                                }
                        }
@@ -655,6 +656,7 @@ public class Vala.MethodCall : Expression {
                                // simple statements, no side effects after method call
                        } else if (!(context.analyzer.current_symbol is Block)) {
                                // can't handle errors in field initializers
+                               error = true;
                                Report.error (source_reference, "Field initializers must not throw errors");
                        } else {
                                // store parent_node as we need to replace the expression in the old parent 
node later on
@@ -670,7 +672,9 @@ public class Vala.MethodCall : Expression {
 
                                // don't set initializer earlier as this changes parent_node and 
parent_statement
                                local.initializer = this;
-                               decl.check (context);
+                               if (!decl.check (context)) {
+                                       error = true;
+                               }
 
                                // move temp variable to insert block to ensure the
                                // variable is in the same block as the declaration
@@ -680,7 +684,9 @@ public class Vala.MethodCall : Expression {
                                context.analyzer.insert_block.add_local_variable (local);
 
                                old_parent_node.replace_expression (this, temp_access);
-                               temp_access.check (context);
+                               if (!temp_access.check (context)) {
+                                       error = true;
+                               }
                        }
                }
 
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index bb718470f..101fc018f 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -238,7 +238,9 @@ public class Vala.PropertyAccessor : Subroutine {
                        }
 
                        body.check (context);
+               }
 
+               if (body != null && !body.error) {
                        var error_types = new ArrayList<DataType> ();
                        body.get_error_types (error_types);
                        foreach (DataType body_error_type in error_types) {
diff --git a/vala/valareturnstatement.vala b/vala/valareturnstatement.vala
index 07eec37c2..3c069f4d5 100644
--- a/vala/valareturnstatement.vala
+++ b/vala/valareturnstatement.vala
@@ -98,6 +98,7 @@ public class Vala.ReturnStatement : CodeNode, Statement {
                }
 
                if (context.analyzer.current_return_type is VoidType) {
+                       error = true;
                        Report.error (source_reference, "Return with value in void function");
                        return false;
                }


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