]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Compact classes don't allow private/class fields and to lock fields
authorRico Tzschichholz <ricotz@ubuntu.com>
Sat, 17 Nov 2018 14:02:01 +0000 (15:02 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sat, 17 Nov 2018 16:24:21 +0000 (17:24 +0100)
This conveniently moves 2 error reports from codegen to semantic check too.

codegen/valaccodebasemodule.vala
codegen/valagtypemodule.vala
tests/Makefile.am
tests/semantic/class-compact-field-class.test [new file with mode: 0644]
tests/semantic/class-compact-field-lock.test [new file with mode: 0644]
tests/semantic/class-compact-field-private.test [new file with mode: 0644]
vala/valaclass.vala
vala/valalockstatement.vala
vala/valaunlockstatement.vala

index 1c352fbc13a1bc47061affacb0ff95217bba8e69..48247a1f80d9c40479046095eb75a4bdbbeeae82 100644 (file)
@@ -1200,12 +1200,6 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                                pop_context ();
                        }
                } else if (f.binding == MemberBinding.CLASS)  {
-                       if (!is_gtypeinstance) {
-                               Report.error (f.source_reference, "class fields are not supported in compact classes");
-                               f.error = true;
-                               return;
-                       }
-
                        if (f.access == SymbolAccessibility.PRIVATE) {
                                var ccall = new CCodeFunctionCall (new CCodeIdentifier ("%s_GET_CLASS_PRIVATE".printf (get_ccode_upper_case_name (cl))));
                                ccall.add_argument (new CCodeIdentifier ("klass"));
index 01d3e5e9783baa9c82abf72cf289382d26431ea6..e46573cdad6bcdbad263eb2a601a21c8ad3c8b40 100644 (file)
@@ -616,10 +616,6 @@ public class Vala.GTypeModule : GErrorModule {
                                string macro = "(G_TYPE_CLASS_GET_PRIVATE (klass, %s, %sClassPrivate))".printf (get_ccode_type_id (cl), get_ccode_name (cl));
                                decl_space.add_type_member_declaration (new CCodeMacroReplacement ("%s_GET_CLASS_PRIVATE(klass)".printf (get_ccode_upper_case_name (cl, null)), macro));
                        }
-               } else {
-                       if (cl.has_private_fields) {
-                               Report.error (cl.source_reference, "Private fields not supported in compact classes");
-                       }
                }
        }
 
index cf7562570d9bfa85c5c5f6c76099fc184e9e7bbe..57c95f9c87f3c703f3a72dd03a18c08fc57838d4 100644 (file)
@@ -514,6 +514,9 @@ TESTS = \
        semantic/chainup-gobject-unsupported-type-property.test \
        semantic/class-base-type-invalid.test \
        semantic/class-base-type-less-accessible.test \
+       semantic/class-compact-field-class.test \
+       semantic/class-compact-field-lock.test \
+       semantic/class-compact-field-private.test \
        semantic/class-compact-derived-instance-field.test \
        semantic/class-compact-interface.test \
        semantic/class-compact-method-baseaccess.test \
diff --git a/tests/semantic/class-compact-field-class.test b/tests/semantic/class-compact-field-class.test
new file mode 100644 (file)
index 0000000..0f00e72
--- /dev/null
@@ -0,0 +1,9 @@
+Invalid Code
+
+[Compact]
+class Foo {
+       public class int i;
+}
+
+void main () {
+}
diff --git a/tests/semantic/class-compact-field-lock.test b/tests/semantic/class-compact-field-lock.test
new file mode 100644 (file)
index 0000000..d4124ee
--- /dev/null
@@ -0,0 +1,13 @@
+Invalid Code
+
+[Compact]
+class Foo {
+       public int i;
+       public void foo () {
+               lock (i) {
+               }
+       }
+}
+
+void main () {
+}
diff --git a/tests/semantic/class-compact-field-private.test b/tests/semantic/class-compact-field-private.test
new file mode 100644 (file)
index 0000000..3356383
--- /dev/null
@@ -0,0 +1,9 @@
+Invalid Code
+
+[Compact]
+class Foo {
+       int i;
+}
+
+void main () {
+}
index 0a3d92b765b629f953c22f9921cdded2ac832cd3..5d8e27592ccd7af36cc5ce0c0f9394833d72b8c0 100644 (file)
@@ -593,6 +593,18 @@ public class Vala.Class : ObjectTypeSymbol {
                }
 
                foreach (Field f in get_fields ()) {
+                       if (is_compact && f.binding != MemberBinding.STATIC) {
+                               //FIXME Should external bindings follow this too?
+                               if (!external_package && f.access == SymbolAccessibility.PRIVATE) {
+                                       Report.error (source_reference, "private fields are not supported in compact classes");
+                                       error = true;
+                               }
+                               if (f.binding == MemberBinding.CLASS) {
+                                       Report.error (f.source_reference, "class fields are not supported in compact classes");
+                                       error = true;
+                               }
+                       }
+
                        f.check (context);
                }
 
index 7099383faff4e85d0b21a2ecfa28bd3225551158..e64d4a206956eb3fab99c2b8a9b7116cb08c75ea 100644 (file)
@@ -118,6 +118,15 @@ public class Vala.LockStatement : CodeNode, Statement {
                        error = true;
                        resource.error = true;
                        Report.error (resource.source_reference, "Only members of the current class are lockable");
+                       return false;
+               }
+
+               /* parent class must not be compact */
+               if (context.analyzer.current_class.is_compact) {
+                       error = true;
+                       resource.error = true;
+                       Report.error (resource.source_reference, "Only members of the non-compact classes are lockable");
+                       return false;
                }
 
                ((Lockable) resource.symbol_reference).lock_used = true;
index 3e49671ee275931c33ecc5c9459ae6f221b49437..d60d5706c5439a4b211137804162c2a527852e34 100644 (file)
@@ -76,6 +76,15 @@ public class Vala.UnlockStatement : CodeNode, Statement {
                        error = true;
                        resource.error = true;
                        Report.error (resource.source_reference, "Only members of the current class are lockable");
+                       return false;
+               }
+
+               /* parent class must not be compact */
+               if (context.analyzer.current_class.is_compact) {
+                       error = true;
+                       resource.error = true;
+                       Report.error (resource.source_reference, "Only members of the non-compact classes are lockable");
+                       return false;
                }
 
                ((Lockable) resource.symbol_reference).lock_used = true;