]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Improve detection of recursive struct declarations 72825e6ef132b5c8729a58e5af756d82c0f60894
authorPrinceton Ferro <princetonferro@gmail.com>
Wed, 29 Jan 2020 04:14:42 +0000 (23:14 -0500)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 29 Jan 2020 08:21:30 +0000 (09:21 +0100)
Introduced with da2d58c95f39fd142dc845f5df9cdcd55be32476

Fixes https://gitlab.gnome.org/GNOME/vala/issues/902

tests/Makefile.am
tests/semantic/struct-recursive-in-struct.test [new file with mode: 0644]
vala/valastruct.vala

index 29c9e7a8dd903a94cb2712a86229c27e83b78f20..ba34f51d2c380ca8eb8c19d53199bfdfae4a07e0 100644 (file)
@@ -846,6 +846,7 @@ TESTS = \
        semantic/struct-field-initializer.test \
        semantic/struct-invalid-base.test \
        semantic/struct-recursive.test \
+       semantic/struct-recursive-in-struct.test \
        semantic/switch-duplicate-label.test \
        semantic/switch-label-not-compatible.test \
        semantic/switch-label-not-constant.test \
diff --git a/tests/semantic/struct-recursive-in-struct.test b/tests/semantic/struct-recursive-in-struct.test
new file mode 100644 (file)
index 0000000..bcf5b8a
--- /dev/null
@@ -0,0 +1,13 @@
+Invalid Code
+
+struct Bar {
+       Foo foo;
+}
+
+struct Foo {
+       Foo next;
+       Foo prev;
+}
+
+void main () {
+}
index 8eff5c7231eedb020207d498ca494c74672cd086..53a952753425e810e16ad8a4060c02b6cc3bc1a4 100644 (file)
@@ -464,15 +464,18 @@ public class Vala.Struct : TypeSymbol {
                return false;
        }
 
-       bool is_recursive_value_type (DataType type) {
+       bool is_recursive_value_type (CodeContext context, DataType type) {
                unowned StructValueType? struct_type = type as StructValueType;
                if (struct_type != null && !struct_type.nullable) {
                        unowned Struct st = (Struct) struct_type.type_symbol;
                        if (st == this) {
                                return true;
                        }
+                       if (!st.check (context)) {
+                               return false;
+                       }
                        foreach (Field f in st.fields) {
-                               if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.variable_type)) {
+                               if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (context, f.variable_type)) {
                                        return true;
                                }
                        }
@@ -512,7 +515,7 @@ public class Vala.Struct : TypeSymbol {
                foreach (Field f in fields) {
                        f.check (context);
 
-                       if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (f.variable_type)) {
+                       if (f.binding == MemberBinding.INSTANCE && is_recursive_value_type (context, f.variable_type)) {
                                error = true;
                                Report.error (f.source_reference, "Recursive value types are not allowed");
                                return false;