Commit bf46b34f authored by Luca Bruno's avatar Luca Bruno Committed by Jürg Billeter

Support derived structs with no fields, report an error otherwise

Fixes bug 622777.
parent a7767b29
......@@ -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 ()) {
......
......@@ -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;
}
}
}
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment