summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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;
+ }
+ }
}