summaryrefslogtreecommitdiff
path: root/vala/valaconstant.vala
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2009-07-10 12:39:17 +0100
committerJürg Billeter <j@bitron.ch>2009-07-10 12:39:17 +0100
commit3b3ffa129f449b5d238c0d32476ea8eef41a6e8d (patch)
treed7a770033b049416e0a75fca15557ad931ac1592 /vala/valaconstant.vala
parentd84ea1c3e772270555d3dcaf436984b63f02318a (diff)
downloadvala-3b3ffa129f449b5d238c0d32476ea8eef41a6e8d.tar.gz
Check type of constants
Fixes bug 587947.
Diffstat (limited to 'vala/valaconstant.vala')
-rw-r--r--vala/valaconstant.vala25
1 files changed, 25 insertions, 0 deletions
diff --git a/vala/valaconstant.vala b/vala/valaconstant.vala
index 81ed913fa..1aa299a54 100644
--- a/vala/valaconstant.vala
+++ b/vala/valaconstant.vala
@@ -170,6 +170,12 @@ public class Vala.Constant : Member, Lockable {
type_reference.check (analyzer);
+ if (!check_const_type (type_reference, analyzer)) {
+ error = true;
+ Report.error (source_reference, "`%s' not supported as type for constants".printf (type_reference.to_string ()));
+ return false;
+ }
+
if (!external) {
if (initializer == null) {
error = true;
@@ -178,6 +184,12 @@ public class Vala.Constant : Member, Lockable {
initializer.target_type = type_reference;
initializer.check (analyzer);
+
+ if (!initializer.value_type.compatible (type_reference)) {
+ error = true;
+ Report.error (source_reference, "Cannot convert from `%s' to `%s'".printf (initializer.value_type.to_string (), type_reference.to_string ()));
+ return false;
+ }
}
}
@@ -190,4 +202,17 @@ public class Vala.Constant : Member, Lockable {
return !error;
}
+
+ bool check_const_type (DataType type, SemanticAnalyzer analyzer) {
+ if (type is ValueType) {
+ return true;
+ } else if (type is ArrayType) {
+ var array_type = type as ArrayType;
+ return check_const_type (array_type.element_type, analyzer);
+ } else if (type.data_type == analyzer.string_type.data_type) {
+ return true;
+ } else {
+ return false;
+ }
+ }
}