[vala] Report error for constants with non-constant expressions
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Report error for constants with non-constant expressions
- Date: Tue, 8 Feb 2011 19:33:21 +0000 (UTC)
commit 6f12ba028dd6442afa25728e530516af7d8a6f0e
Author: Jürg Billeter <j bitron ch>
Date: Tue Feb 8 19:59:25 2011 +0100
Report error for constants with non-constant expressions
vala/valaconstant.vala | 8 +++++++-
vala/valainitializerlist.vala | 11 ++++++++++-
vala/valamemberaccess.vala | 6 +++++-
vala/valaunaryexpression.vala | 11 ++++++++++-
4 files changed, 32 insertions(+), 4 deletions(-)
---
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index 974fee4..fab450c 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 a6208ce..e99a415 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 e898318..f7ebe5a 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 661a8fb..930e5ce 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 ();
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]