]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Do not split conditional expressions in asserts
authorJürg Billeter <j@bitron.ch>
Sun, 18 Oct 2009 12:41:17 +0000 (14:41 +0200)
committerJürg Billeter <j@bitron.ch>
Sun, 18 Oct 2009 12:41:17 +0000 (14:41 +0200)
Fixes bug 577619.

vala/valabinaryexpression.vala
vala/valamethodcall.vala
vapi/glib-2.0.vapi

index b4b35c4e701c633c4e9909b86c1f88ec75d6f31a..27477239e5f91885ad163c5a3ea2fe717d544b07 100644 (file)
@@ -139,6 +139,14 @@ public class Vala.BinaryExpression : Expression {
                return left.is_non_null () && right.is_non_null ();
        }
 
+       bool in_assert () {
+               CodeNode expr = this;
+               while (expr != null && !(expr is MethodCall && ((MethodCall) expr).is_assert)) {
+                       expr = expr.parent_node;
+               }
+               return (expr != null);
+       }
+
        public override bool check (SemanticAnalyzer analyzer) {
                if (checked) {
                        return !error;
@@ -148,7 +156,14 @@ public class Vala.BinaryExpression : Expression {
 
                // some expressions are not in a block,
                // for example, expressions in method contracts
-               if (analyzer.current_symbol is Block
+               //
+               // also don't convert expressions in asserts to not execute
+               // assert expressions when disabled on the C level and
+               // avoid unusable assertion messages
+               // reachability analysis and error handling should never be
+               // necessary for assertion expressions, so it is ok to avoid
+               // the split
+               if (analyzer.current_symbol is Block && !in_assert ()
                    && (operator == BinaryOperator.AND || operator == BinaryOperator.OR)) {
                        // convert conditional expression into if statement
                        // required for flow analysis and exception handling
index aafb9485dc3aafed398a9f4e277c8e5a399bc1c0..aedeb96a4392095ee78c1a6b8593a40f7d762bff 100644 (file)
@@ -39,6 +39,8 @@ public class Vala.MethodCall : Expression {
 
        public bool is_yield_expression { get; set; }
 
+       public bool is_assert { get; private set; }
+
        public Expression _call;
        
        private List<Expression> argument_list = new ArrayList<Expression> ();
@@ -131,6 +133,10 @@ public class Vala.MethodCall : Expression {
                        if (ma.inner != null) {
                                target_object_type = ma.inner.value_type;
                        }
+
+                       if (ma.symbol_reference != null && ma.symbol_reference.get_attribute ("Assert") != null) {
+                               this.is_assert = true;
+                       }
                }
 
                var mtype = call.value_type;
index 38b590ed6b9adedf797b06d2f758455570022721..2d313843fbefde399c3d9a44444d9a1cb8be87f8 100644 (file)
@@ -1672,6 +1672,7 @@ namespace GLib {
        public static void warn_if_fail (bool expr);
        public static void warn_if_reached ();
 
+       [Assert]
        public static void assert (bool expr);
        [NoReturn]
        public static void assert_not_reached ();