[vala] analyzer: Fix critical when catch clause does not catch an ErrorType



commit 5d96dcfc5f65da2ef2c3c04614bef7853eeebcf2
Author: Luca Bruno <lucabru src gnome org>
Date:   Sat Dec 14 14:41:26 2013 +0100

    analyzer: Fix critical when catch clause does not catch an ErrorType
    
    Based on patch by Severin Heiniger.
    
    Fixes bug 670806.

 vala/valacatchclause.vala  |    6 +++++-
 vala/valaflowanalyzer.vala |    2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)
---
diff --git a/vala/valacatchclause.vala b/vala/valacatchclause.vala
index b2f20a4..59a28e2 100644
--- a/vala/valacatchclause.vala
+++ b/vala/valacatchclause.vala
@@ -117,6 +117,11 @@ public class Vala.CatchClause : CodeNode {
                checked = true;
 
                if (error_type != null) {
+                       if (!(error_type is ErrorType)) {
+                               Report.error (source_reference, "clause must catch a valid error type, found 
`%s' instead".printf (error_type.to_string ()));
+                               error = true;
+                       }
+
                        if (variable_name != null) {
                                error_variable = new LocalVariable (error_type.copy (), variable_name);
 
@@ -131,7 +136,6 @@ public class Vala.CatchClause : CodeNode {
                }
 
                error_type.check (context);
-
                body.check (context);
 
                return !error;
diff --git a/vala/valaflowanalyzer.vala b/vala/valaflowanalyzer.vala
index 62dc58a..9f94a42 100644
--- a/vala/valaflowanalyzer.vala
+++ b/vala/valaflowanalyzer.vala
@@ -943,7 +943,7 @@ public class Vala.FlowAnalyzer : CodeVisitor {
                for (int i = catch_clauses.size - 1; i >= 0; i--) {
                        var catch_clause = catch_clauses[i];
                        if (catch_clause.error_type != null) {
-                               var error_type = catch_clause.error_type as ErrorType;
+                               var error_type = (ErrorType) catch_clause.error_type;
                                jump_stack.add (new JumpTarget.error_target (new BasicBlock (), catch_clause, 
catch_clause.error_type.data_type as ErrorDomain, error_type.error_code, null));
                        } else {
                                jump_stack.add (new JumpTarget.error_target (new BasicBlock (), catch_clause, 
null, null, null));


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