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



commit c235e69f6314838b7f5a24448abb7abcb7ab87a4
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Wed Feb 19 22:27:22 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     |  8 +++++++-
 vala/valamethodcall.vala       | 10 ++++++++--
 vala/valapropertyaccessor.vala |  2 ++
 vala/valareturnstatement.vala  |  1 +
 vala/valathrowstatement.vala   |  3 +++
 9 files changed, 35 insertions(+), 12 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..6a0ccb6ff 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -307,7 +307,12 @@ public class Vala.MemberAccess : Expression {
 
                        if (symbol_reference == null && source_reference != null) {
                                foreach (UsingDirective ns in source_reference.using_directives) {
-                                       var local_sym = ns.namespace_symbol.scope.lookup (member_name);
+                                       unowned Namespace? ns_symbol = ns.namespace_symbol as Namespace;
+                                       if (ns_symbol == null) {
+                                               // unresolved
+                                               continue;
+                                       }
+                                       var local_sym = ns_symbol.scope.lookup (member_name);
                                        if (local_sym != null) {
                                                if (symbol_reference != null && symbol_reference != 
local_sym) {
                                                        error = true;
@@ -825,6 +830,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 026dd1f28..2e30bf39f 100644
--- a/vala/valareturnstatement.vala
+++ b/vala/valareturnstatement.vala
@@ -108,6 +108,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;
                }
diff --git a/vala/valathrowstatement.vala b/vala/valathrowstatement.vala
index 9349b1818..34ec7cb19 100644
--- a/vala/valathrowstatement.vala
+++ b/vala/valathrowstatement.vala
@@ -73,6 +73,9 @@ public class Vala.ThrowStatement : CodeNode, Statement {
        }
 
        public override void get_error_types (Collection<DataType> collection, SourceReference? 
source_reference = null) {
+               if (!checked || error) {
+                       return;
+               }
                if (source_reference == null) {
                        source_reference = this.source_reference;
                }


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