[vala/0.42] vala: Compact classes don't allow private/class fields and to lock fields
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.42] vala: Compact classes don't allow private/class fields and to lock fields
- Date: Mon, 26 Nov 2018 09:13:53 +0000 (UTC)
commit f8652eaf8c412a58dfbd808c2bc2a9d241a8bee4
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Nov 17 15:02:01 2018 +0100
vala: Compact classes don't allow private/class fields and to lock fields
This conveniently moves 2 error reports from codegen to semantic check too.
codegen/valaccodebasemodule.vala | 6 ------
codegen/valagtypemodule.vala | 4 ----
tests/Makefile.am | 3 +++
tests/semantic/class-compact-field-class.test | 9 +++++++++
tests/semantic/class-compact-field-lock.test | 13 +++++++++++++
tests/semantic/class-compact-field-private.test | 9 +++++++++
vala/valaclass.vala | 12 ++++++++++++
vala/valalockstatement.vala | 9 +++++++++
vala/valaunlockstatement.vala | 9 +++++++++
9 files changed, 64 insertions(+), 10 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index db822e136..5c0c81b4d 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -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"));
diff --git a/codegen/valagtypemodule.vala b/codegen/valagtypemodule.vala
index 62a8e4459..63be8e092 100644
--- a/codegen/valagtypemodule.vala
+++ b/codegen/valagtypemodule.vala
@@ -596,10 +596,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");
- }
}
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 4fbb9b213..262e5fa93 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -511,6 +511,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
index 000000000..0f00e72d1
--- /dev/null
+++ b/tests/semantic/class-compact-field-class.test
@@ -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
index 000000000..d4124ee42
--- /dev/null
+++ b/tests/semantic/class-compact-field-lock.test
@@ -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
index 000000000..335638355
--- /dev/null
+++ b/tests/semantic/class-compact-field-private.test
@@ -0,0 +1,9 @@
+Invalid Code
+
+[Compact]
+class Foo {
+ int i;
+}
+
+void main () {
+}
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index d54a67ff2..c307d0e93 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -547,6 +547,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);
}
diff --git a/vala/valalockstatement.vala b/vala/valalockstatement.vala
index 7099383fa..e64d4a206 100644
--- a/vala/valalockstatement.vala
+++ b/vala/valalockstatement.vala
@@ -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;
diff --git a/vala/valaunlockstatement.vala b/vala/valaunlockstatement.vala
index 3e49671ee..d60d5706c 100644
--- a/vala/valaunlockstatement.vala
+++ b/vala/valaunlockstatement.vala
@@ -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;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]