[vala/912-fix-invalid-cast-from-valainvalidtype-to-valaerrortype: 5/5] Check type before cast to Vala.ErrorType



commit 3b231aad1b6919a08125964579c7a40d349c3d8c
Author: Daniel Espinosa <esodan gmail com>
Date:   Wed Feb 19 10:48:07 2020 -0600

    Check type before cast to Vala.ErrorType

 vala/valaconstructor.vala      | 8 ++++++--
 vala/valacreationmethod.vala   | 8 ++++++--
 vala/valaflowanalyzer.vala     | 8 ++++++--
 vala/valapropertyaccessor.vala | 8 ++++++--
 4 files changed, 24 insertions(+), 8 deletions(-)
---
diff --git a/vala/valaconstructor.vala b/vala/valaconstructor.vala
index a4844c728..f04ff01b1 100644
--- a/vala/valaconstructor.vala
+++ b/vala/valaconstructor.vala
@@ -80,8 +80,12 @@ public class Vala.Constructor : Subroutine {
                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_error_type is ErrorType) {
+                               if (!((ErrorType) body_error_type).dynamic_error) {
+                                       Report.warning (body_error_type.source_reference, "unhandled error 
`%s'".printf (body_error_type.to_string()));
+                               }
+                       } else {
+                               Report.warning (body_error_type.source_reference, "trying to use a non 
ErrorType object: Internal Error");
                        }
                }
 
diff --git a/vala/valacreationmethod.vala b/vala/valacreationmethod.vala
index 23d40fd39..d199e4dea 100644
--- a/vala/valacreationmethod.vala
+++ b/vala/valacreationmethod.vala
@@ -194,8 +194,12 @@ public class Vala.CreationMethod : Method {
                                                }
                                        }
                                }
-                               if (!can_propagate_error && !((ErrorType) body_error_type).dynamic_error) {
-                                       Report.warning (body_error_type.source_reference, "unhandled error 
`%s'".printf (body_error_type.to_string()));
+                               if (body_error_type is ErrorType) {
+                                       if (!can_propagate_error && !((ErrorType) 
body_error_type).dynamic_error) {
+                                               Report.warning (body_error_type.source_reference, "unhandled 
error `%s'".printf (body_error_type.to_string()));
+                                       }
+                               } else {
+                                       Report.warning (body_error_type.source_reference, "trying to use a 
non ErrorType object: Internal Error");
                                }
                        }
                }
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 978ab94f8..ce629e5fe 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -989,8 +989,12 @@ public class Vala.FlowAnalyzer : CodeVisitor {
 
                        if (catch_clause.error_type != null) {
                                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));
+                                       ErrorCode error_code = new Vala.ErrorCode ("invalid-code");
+                                       if (catch_clause.error_type is ErrorType) {
+                                               error_code = ((ErrorType) catch_clause.error_type).error_code;
+                                       }
+
+                                       jump_stack.add (new JumpTarget.error_target (error_block, 
catch_clause, catch_clause.error_type.type_symbol as ErrorDomain, error_code, null));
                                } else {
                                        unowned Class? error_class = catch_clause.error_type.type_symbol as 
Class;
                                        jump_stack.add (new JumpTarget.error_target (error_block, 
catch_clause, null, null, error_class));
diff --git a/vala/valapropertyaccessor.vala b/vala/valapropertyaccessor.vala
index bb718470f..2634e5c86 100644
--- a/vala/valapropertyaccessor.vala
+++ b/vala/valapropertyaccessor.vala
@@ -242,8 +242,12 @@ public class Vala.PropertyAccessor : Subroutine {
                        var error_types = new ArrayList<DataType> ();
                        body.get_error_types (error_types);
                        foreach (DataType body_error_type in error_types) {
-                               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_error_type is ErrorType) {
+                                       if (!((ErrorType) body_error_type).dynamic_error) {
+                                               Report.warning (body_error_type.source_reference, "unhandled 
error `%s'".printf (body_error_type.to_string()));
+                                       }
+                               } else {
+                                       Report.warning (body_error_type.source_reference, "trying to use a 
non ErrorType object: Internal Error");
                                }
                        }
                }


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