]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report error for constants with non-constant expressions
authorJürg Billeter <j@bitron.ch>
Tue, 8 Feb 2011 18:59:25 +0000 (19:59 +0100)
committerJürg Billeter <j@bitron.ch>
Tue, 8 Feb 2011 19:05:29 +0000 (20:05 +0100)
vala/valaconstant.vala
vala/valainitializerlist.vala
vala/valamemberaccess.vala
vala/valaunaryexpression.vala

index 974fee4241fb53ca79eabf54b7ef7acaed974d2e..fab450c17aaeb1450c2dc20a00bcab71deec45dd 100644 (file)
@@ -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) {
index a6208ced929f002790acc828c8c0bffa1be35240..e99a415f5a4a8577cccc1a30cf9781f720847987 100644 (file)
@@ -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 ()) {
index e8983185b433850fd1966b6b9be648042fb1e535..f7ebe5acedb76c76a4d378c121eba91cb5ca1db9 100644 (file)
@@ -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;
                }
index 661a8fb5361461b5a191ad964064303ebf7a1364..930e5ce06bcec11e6955292cddbd62e66e220fc2 100644 (file)
@@ -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 ();
        }