diff options
-rw-r--r-- | codegen/valaccodebasemodule.vala | 6 | ||||
-rw-r--r-- | codegen/valagtypemodule.vala | 4 | ||||
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/semantic/class-compact-field-class.test | 9 | ||||
-rw-r--r-- | tests/semantic/class-compact-field-lock.test | 13 | ||||
-rw-r--r-- | tests/semantic/class-compact-field-private.test | 9 | ||||
-rw-r--r-- | vala/valaclass.vala | 12 | ||||
-rw-r--r-- | vala/valalockstatement.vala | 9 | ||||
-rw-r--r-- | vala/valaunlockstatement.vala | 9 |
9 files changed, 64 insertions, 10 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 1c352fbc1..48247a1f8 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 01d3e5e97..e46573cda 100644 --- a/codegen/valagtypemodule.vala +++ b/codegen/valagtypemodule.vala @@ -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"); - } } } diff --git a/tests/Makefile.am b/tests/Makefile.am index cf7562570..57c95f9c8 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 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 0a3d92b76..5d8e27592 100644 --- a/vala/valaclass.vala +++ b/vala/valaclass.vala @@ -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); } 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; |