]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Report error for recursive value types da2d58c95f39fd142dc845f5df9cdcd55be32476
authorJürg Billeter <j@bitron.ch>
Sat, 6 Jun 2009 16:22:15 +0000 (18:22 +0200)
committerJürg Billeter <j@bitron.ch>
Sat, 6 Jun 2009 16:22:15 +0000 (18:22 +0200)
Fixes bug 584573.

vala/valastruct.vala

index 8f5fbcaa2b37db5586e4999c90530dcfe9c7f694..166edba43d0f9f38c26e4aaed874ff47fe08791b 100644 (file)
@@ -690,6 +690,22 @@ public class Vala.Struct : TypeSymbol {
                return false;
        }
 
+       bool is_recursive_value_type (DataType type) {
+               var struct_type = type as StructValueType;
+               if (struct_type != null) {
+                       var st = (Struct) struct_type.type_symbol;
+                       if (st == this) {
+                               return true;
+                       }
+                       foreach (Field f in st.fields) {
+                               if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.field_type)) {
+                                       return true;
+                               }
+                       }
+               }
+               return false;
+       }
+
        public override bool check (SemanticAnalyzer analyzer) {
                if (checked) {
                        return !error;
@@ -725,6 +741,12 @@ public class Vala.Struct : TypeSymbol {
 
                foreach (Field f in fields) {
                        f.check (analyzer);
+
+                       if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.field_type)) {
+                               error = true;
+                               Report.error (f.source_reference, "Recursive value types are not allowed");
+                               return false;
+                       }
                }
 
                foreach (Constant c in constants) {