[vala/wip/ricotz/lsp-rev: 1/3] WIP vala: Improve dealing with errornous nodes



commit 0b8077a960cba3f094c6c026b1c3c3962140f474
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Feb 18 12:54:30 2020 +0100

    WIP vala: Improve dealing with errornous nodes

 vala/valaarraytype.vala        |  4 +++-
 vala/valabinaryexpression.vala |  2 +-
 vala/valaelementaccess.vala    |  3 +++
 vala/valalambdaexpression.vala |  6 ++++--
 vala/valamethodcall.vala       | 13 +++++++++----
 vala/valaparameter.vala        |  2 +-
 vala/valathrowstatement.vala   |  8 +++++---
 7 files changed, 26 insertions(+), 12 deletions(-)
---
diff --git a/vala/valaarraytype.vala b/vala/valaarraytype.vala
index bb6dceb44..e41fb7904 100644
--- a/vala/valaarraytype.vala
+++ b/vala/valaarraytype.vala
@@ -91,7 +91,9 @@ public class Vala.ArrayType : ReferenceType {
        }
 
        public override Symbol? get_member (string member_name) {
-               if (member_name == "length") {
+               if (error) {
+                       // don't try anything
+               } else if (member_name == "length") {
                        return get_length_field ();
                } else if (member_name == "move") {
                        return get_move_method ();
diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala
index 60c911677..1022060a8 100644
--- a/vala/valabinaryexpression.vala
+++ b/vala/valabinaryexpression.vala
@@ -328,7 +328,7 @@ public class Vala.BinaryExpression : Expression {
                        return false;
                }
 
-               if (operator != BinaryOperator.IN && right.value_type == null) {
+               if (right.value_type == null) {
                        Report.error (right.source_reference, "invalid right operand");
                        error = true;
                        return false;
diff --git a/vala/valaelementaccess.vala b/vala/valaelementaccess.vala
index 9ecc6c67e..40a8c196b 100644
--- a/vala/valaelementaccess.vala
+++ b/vala/valaelementaccess.vala
@@ -195,8 +195,10 @@ public class Vala.ElementAccess : Expression {
                        }
 
                        if (array_type.rank < get_indices ().size) {
+                               error = true;
                                Report.error (source_reference, "%d extra indices for element access".printf 
(get_indices ().size - array_type.rank));
                        } else if (array_type.rank > get_indices ().size) {
+                               error = true;
                                Report.error (source_reference, "%d missing indices for element 
access".printf (array_type.rank - get_indices ().size));
                        }
                } else if (pointer_type != null && 
!pointer_type.base_type.is_reference_type_or_type_parameter ()) {
@@ -229,6 +231,7 @@ public class Vala.ElementAccess : Expression {
 
                        error = true;
                        Report.error (source_reference, "The expression `%s' does not denote an array".printf 
(container.value_type.to_string ()));
+                       return false;
                }
 
                if (index_int_type_check) {
diff --git a/vala/valalambdaexpression.vala b/vala/valalambdaexpression.vala
index 4fb7f4564..5589640d1 100644
--- a/vala/valalambdaexpression.vala
+++ b/vala/valalambdaexpression.vala
@@ -233,7 +233,9 @@ public class Vala.LambdaExpression : Expression {
                /* lambda expressions should be usable like MemberAccess of a method */
                symbol_reference = method;
 
-               method.check (context);
+               if (!method.check (context)) {
+                       error = true;
+               }
 
                value_type = new MethodType (method);
                value_type.value_owned = target_type.value_owned;
@@ -249,7 +251,7 @@ public class Vala.LambdaExpression : Expression {
 
        public override void get_used_variables (Collection<Variable> collection) {
                // require captured variables to be initialized
-               if (method.closure) {
+               if (!error && method.closure) {
                        method.get_captured_variables ((Collection<LocalVariable>) collection);
                }
        }
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index b9772fed8..d57945bf1 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -155,8 +155,10 @@ public class Vala.MethodCall : Expression {
                } else if (mtype is ObjectType) {
                        // constructor
                        unowned Class cl = (Class) ((ObjectType) mtype).type_symbol;
-                       unowned Method m = cl.default_construction_method;
-                       m.get_error_types (collection, source_reference);
+                       unowned Method? m = cl.default_construction_method;
+                       if (m != null) {
+                               m.get_error_types (collection, source_reference);
+                       }
                } else if (mtype is DelegateType) {
                        unowned Delegate d = ((DelegateType) mtype).delegate_symbol;
                        d.get_error_types (collection, source_reference);
@@ -473,7 +475,10 @@ public class Vala.MethodCall : Expression {
 
                bool force_lambda_method_closure = false;
                foreach (Expression arg in argument_list) {
-                       arg.check (context);
+                       if (!arg.check (context)) {
+                               error = true;
+                               continue;
+                       }
 
                        if (arg is LambdaExpression && ((LambdaExpression) arg).method.closure) {
                                force_lambda_method_closure = true;
@@ -481,7 +486,7 @@ public class Vala.MethodCall : Expression {
                }
                // force all lambda arguments using the same closure scope
                // TODO https://gitlab.gnome.org/GNOME/vala/issues/59
-               if (force_lambda_method_closure) {
+               if (!error && force_lambda_method_closure) {
                        foreach (Expression arg in argument_list) {
                                unowned LambdaExpression? lambda = arg as LambdaExpression;
                                if (lambda != null && lambda.method.binding != MemberBinding.STATIC) {
diff --git a/vala/valaparameter.vala b/vala/valaparameter.vala
index e447612d3..052b06ce8 100644
--- a/vala/valaparameter.vala
+++ b/vala/valaparameter.vala
@@ -176,7 +176,7 @@ public class Vala.Parameter : Variable {
                        }
                }
 
-               if (initializer != null) {
+               if (initializer != null && !initializer.error) {
                        if (initializer is NullLiteral
                            && !variable_type.nullable
                            && direction != ParameterDirection.OUT) {
diff --git a/vala/valathrowstatement.vala b/vala/valathrowstatement.vala
index 9349b1818..86970c485 100644
--- a/vala/valathrowstatement.vala
+++ b/vala/valathrowstatement.vala
@@ -76,9 +76,11 @@ public class Vala.ThrowStatement : CodeNode, Statement {
                if (source_reference == null) {
                        source_reference = this.source_reference;
                }
-               var error_type = error_expression.value_type.copy ();
-               error_type.source_reference = source_reference;
-               collection.add (error_type);
+               if (!error_expression.error) {
+                       var error_type = error_expression.value_type.copy ();
+                       error_type.source_reference = source_reference;
+                       collection.add (error_type);
+               }
        }
 
        public override bool check (CodeContext context) {


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