[vala] codegen: Use equal method of base-struct for derived structs



commit a18c17e614ad5d3e8b6af31e1b986f717af30cbb
Author: Rico Tzschichholz <ricotz t-online de>
Date:   Mon Dec 17 21:27:27 2012 +0100

    codegen: Use equal method of base-struct for derived structs
    
    https://bugzilla.gnome.org/show_bug.cgi?id=690380

 codegen/valaccodebasemodule.vala |    4 ++++
 tests/Makefile.am                |    1 +
 tests/structs/bug690380.vala     |   18 ++++++++++++++++++
 3 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index f84ed67..93d04ee 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2686,6 +2686,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
 			return equal_func;
 		}
 
+		if (st.base_struct != null) {
+			return generate_struct_equal_function (st.base_struct);
+		}
+
 		var function = new CCodeFunction (equal_func, "gboolean");
 		function.modifiers = CCodeModifiers.STATIC;
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 93dc65d..eedf8ce 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -88,6 +88,7 @@ TESTS = \
 	structs/bug667890.vala \
 	structs/bug669580.vala \
 	structs/bug685177.vala \
+	structs/bug690380.vala \
 	delegates/delegates.vala \
 	delegates/bug539166.vala \
 	delegates/bug595610.vala \
diff --git a/tests/structs/bug690380.vala b/tests/structs/bug690380.vala
new file mode 100644
index 0000000..38fcc83
--- /dev/null
+++ b/tests/structs/bug690380.vala
@@ -0,0 +1,18 @@
+struct Foo {
+	int i;
+}
+
+struct Bar : Foo {
+}
+
+void main () {
+	var f1 = Foo () { i = 42 };
+	var f2 = Foo () { i = 42 };
+
+	assert (f1 == f2);
+
+	var b1 = Bar () { i = 42 };
+	var b2 = Bar () { i = 42 };
+
+	assert (b1 == b2);
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]