From: Jürg Billeter Date: Tue, 8 Feb 2011 18:59:25 +0000 (+0100) Subject: Report error for constants with non-constant expressions X-Git-Tag: 0.11.6~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6f12ba028dd6442afa25728e530516af7d8a6f0e;p=thirdparty%2Fvala.git Report error for constants with non-constant expressions --- diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala index 974fee424..fab450c17 100644 --- a/vala/valaconstant.vala +++ b/vala/valaconstant.vala @@ -1,6 +1,6 @@ /* valaconstant.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2011 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -202,6 +202,12 @@ public class Vala.Constant : Symbol, Lockable { Report.error (source_reference, "Cannot convert from `%s' to `%s'".printf (value.value_type.to_string (), type_reference.to_string ())); return false; } + + if (!value.is_constant ()) { + error = true; + Report.error (value.source_reference, "Value must be constant"); + return false; + } } } else { if (value != null) { diff --git a/vala/valainitializerlist.vala b/vala/valainitializerlist.vala index a6208ced9..e99a415f5 100644 --- a/vala/valainitializerlist.vala +++ b/vala/valainitializerlist.vala @@ -1,6 +1,6 @@ /* valainitializerlist.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2011 Jürg Billeter * Copyright (C) 2006-2008 Raffaele Sandrini * * This library is free software; you can redistribute it and/or @@ -76,6 +76,15 @@ public class Vala.InitializerList : Expression { visitor.visit_initializer_list (this); } + public override bool is_constant () { + foreach (Expression initializer in initializers) { + if (!initializer.is_constant ()) { + return false; + } + } + return true; + } + public override bool is_pure () { foreach (Expression initializer in initializers) { if (!initializer.is_pure ()) { diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala index e8983185b..f7ebe5ace 100644 --- a/vala/valamemberaccess.vala +++ b/vala/valamemberaccess.vala @@ -1,6 +1,6 @@ /* valamemberaccess.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2011 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -166,8 +166,12 @@ public class Vala.MemberAccess : Expression { } public override bool is_constant () { + var method = symbol_reference as Method; if (symbol_reference is Constant) { return true; + } else if (method != null && + (method.binding == MemberBinding.STATIC || prototype_access)) { + return true; } else { return false; } diff --git a/vala/valaunaryexpression.vala b/vala/valaunaryexpression.vala index 661a8fb53..930e5ce06 100644 --- a/vala/valaunaryexpression.vala +++ b/vala/valaunaryexpression.vala @@ -1,6 +1,6 @@ /* valaunaryexpression.vala * - * Copyright (C) 2006-2010 Jürg Billeter + * Copyright (C) 2006-2011 Jürg Billeter * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -100,6 +100,15 @@ public class Vala.UnaryExpression : Expression { return false; } + if (operator == UnaryOperator.REF || operator == UnaryOperator.OUT) { + var field = inner.symbol_reference as Field; + if (field != null && field.binding == MemberBinding.STATIC) { + return true; + } else { + return false; + } + } + return inner.is_constant (); }