From: Jürg Billeter Date: Sun, 18 Oct 2009 12:41:17 +0000 (+0200) Subject: Do not split conditional expressions in asserts X-Git-Tag: 0.7.8~38 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e818c1d8dc1a7683b220ed5cb0ebad69cd02ad0;p=thirdparty%2Fvala.git Do not split conditional expressions in asserts Fixes bug 577619. --- diff --git a/vala/valabinaryexpression.vala b/vala/valabinaryexpression.vala index b4b35c4e7..27477239e 100644 --- a/vala/valabinaryexpression.vala +++ b/vala/valabinaryexpression.vala @@ -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 diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala index aafb9485d..aedeb96a4 100644 --- a/vala/valamethodcall.vala +++ b/vala/valamethodcall.vala @@ -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 argument_list = new ArrayList (); @@ -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; diff --git a/vapi/glib-2.0.vapi b/vapi/glib-2.0.vapi index 38b590ed6..2d313843f 100644 --- a/vapi/glib-2.0.vapi +++ b/vapi/glib-2.0.vapi @@ -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 ();