[vala] Support derived structs with no fields, report an error otherwise
- From: Jürg Billeter <juergbi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Support derived structs with no fields, report an error otherwise
- Date: Mon, 28 Jun 2010 21:45:47 +0000 (UTC)
commit bf46b34f9e262d29720d7d65191969abc838ba83
Author: Luca Bruno <lethalman88 gmail com>
Date: Mon Jun 28 10:40:46 2010 +0200
Support derived structs with no fields, report an error otherwise
Fixes bug 622777.
codegen/valaccodestructmodule.vala | 8 ++++++--
vala/valaclass.vala | 1 +
vala/valastruct.vala | 17 +++++++++++++----
3 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/codegen/valaccodestructmodule.vala b/codegen/valaccodestructmodule.vala
index d84cbb7..4b3587a 100644
--- a/codegen/valaccodestructmodule.vala
+++ b/codegen/valaccodestructmodule.vala
@@ -103,9 +103,13 @@ public class Vala.CCodeStructModule : CCodeBaseModule {
}
}
- decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
+ if (st.base_struct == null) {
+ decl_space.add_type_declaration (new CCodeTypeDefinition ("struct _%s".printf (st.get_cname ()), new CCodeVariableDeclarator (st.get_cname ())));
- decl_space.add_type_definition (instance_struct);
+ decl_space.add_type_definition (instance_struct);
+ } else {
+ decl_space.add_type_declaration (new CCodeTypeDefinition (st.base_struct.get_cname (), new CCodeVariableDeclarator (st.get_cname ())));
+ }
var function = new CCodeFunction (st.get_dup_function (), st.get_cname () + "*");
if (st.is_private_symbol ()) {
diff --git a/vala/valaclass.vala b/vala/valaclass.vala
index 54916c5..91fa016 100644
--- a/vala/valaclass.vala
+++ b/vala/valaclass.vala
@@ -1053,6 +1053,7 @@ public class Vala.Class : ObjectTypeSymbol {
if (f.binding == MemberBinding.INSTANCE) {
error = true;
Report.error (source_reference, "derived compact classes may not have instance fields");
+ break;
}
}
}
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index bcfa13e..180c67e 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -828,10 +828,19 @@ public class Vala.Struct : TypeSymbol {
prop.check (analyzer);
}
- if (!external && !external_package && base_type == null && get_fields ().size == 0
- && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) {
- error = true;
- Report.error (source_reference, "structs cannot be empty: %s".printf(name));
+ if (!external && !external_package) {
+ if (base_type == null && get_fields ().size == 0 && !is_boolean_type () && !is_integer_type () && !is_floating_type ()) {
+ error = true;
+ Report.error (source_reference, "structs cannot be empty: %s".printf(name));
+ } else if (base_type != null) {
+ foreach (Field f in fields) {
+ if (f.binding == MemberBinding.INSTANCE) {
+ error = true;
+ Report.error (source_reference, "derived structs may not have instance fields");
+ break;
+ }
+ }
+ }
}
analyzer.current_source_file = old_source_file;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]