2008-04-16 Jürg Billeter <j@bitron.ch>
+ * gobject/valaccodegenerator.vala,
+ gobject/valaccodegeneratorinvocationexpression.vala,
+ gobject/valaccodegeneratormemberaccess.vala:
+
+ Fix base access with virtual interface methods, fixes bug 528457
+
+ * tests/classes-methods.vala: test base access
+
+2008-04-16 Jürg Billeter <j@bitron.ch>
+
* vala/valaparser.vala: improve error handling, fixes bug 528431
2008-04-16 Jürg Billeter <j@bitron.ch>
var mt = (MethodType) expression_type;
var method = mt.method_symbol;
- if (method.base_interface_method != null) {
- method = method.base_interface_method;
- } else if (method.base_method != null) {
+ if (method.base_method != null) {
method = method.base_method;
+ } else if (method.base_interface_method != null) {
+ method = method.base_interface_method;
}
return new CCodeIdentifier (generate_delegate_wrapper (method, dt.delegate_symbol));
CCodeExpression instance;
if (m != null && m.instance) {
var base_method = m;
- if (m.base_interface_method != null) {
- base_method = m.base_interface_method;
- } else if (m.base_method != null) {
+ if (m.base_method != null) {
base_method = m.base_method;
+ } else if (m.base_interface_method != null) {
+ base_method = m.base_interface_method;
}
DataType instance_expression_type;
var m = (Method) expr.symbol_reference;
if (expr.inner is BaseAccess) {
- if (m.base_interface_method != null) {
- var base_iface = (Interface) m.base_interface_method.parent_symbol;
- string parent_iface_var = "%s_%s_parent_iface".printf (current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
-
- expr.ccodenode = new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.name);
- return;
- } else if (m.base_method != null) {
+ if (m.base_method != null) {
var base_class = (Class) m.base_method.parent_symbol;
var vcast = new CCodeFunctionCall (new CCodeIdentifier ("%s_CLASS".printf (base_class.get_upper_case_cname (null))));
vcast.add_argument (new CCodeIdentifier ("%s_parent_class".printf (current_class.get_lower_case_cname (null))));
expr.ccodenode = new CCodeMemberAccess.pointer (vcast, m.name);
return;
+ } else if (m.base_interface_method != null) {
+ var base_iface = (Interface) m.base_interface_method.parent_symbol;
+ string parent_iface_var = "%s_%s_parent_iface".printf (current_class.get_lower_case_cname (null), base_iface.get_lower_case_cname (null));
+
+ expr.ccodenode = new CCodeMemberAccess.pointer (new CCodeIdentifier (parent_iface_var), m.name);
+ return;
}
}
- if (m.base_interface_method != null) {
- expr.ccodenode = new CCodeIdentifier (m.base_interface_method.get_cname ());
- } else if (m.base_method != null) {
+ if (m.base_method != null) {
var binding = CCodeMethodBinding.get (m.base_method);
if (!binding.has_wrapper) {
var inst = pub_inst;
} else {
expr.ccodenode = new CCodeIdentifier (m.base_method.get_cname ());
}
+ } else if (m.base_interface_method != null) {
+ expr.ccodenode = new CCodeIdentifier (m.base_interface_method.get_cname ());
} else {
expr.ccodenode = new CCodeIdentifier (m.get_cname ());
}
test_classes_methods_ref_parameters ();
+ BaseAccess.test ();
+
return 0;
}
}
class Maman.DeepDerived : AbstractDerived {
}
+// http://bugzilla.gnome.org/show_bug.cgi?id=528457
+namespace Maman.BaseAccess {
+ public interface IFoo : Object {
+ public abstract int interface_method ();
+
+ public abstract int virtual_interface_method ();
+ }
+
+ public class Foo : Object, IFoo {
+ public virtual int virtual_method () {
+ return 1;
+ }
+
+ public int interface_method () {
+ return 2;
+ }
+
+ public virtual int virtual_interface_method () {
+ return 3;
+ }
+ }
+
+ public class Bar : Foo {
+ public override int virtual_method () {
+ return base.virtual_method () * 10 + 4;
+ }
+
+ public override int virtual_interface_method () {
+ return base.virtual_interface_method () * 10 + 5;
+ }
+ }
+
+ public class FooBar : Foo, IFoo {
+ public int interface_method () {
+ return base.interface_method () * 10 + 6;
+ }
+
+ public int virtual_interface_method () {
+ return -1;
+ }
+ }
+
+ public void test () {
+ var bar = new Bar ();
+ var foobar = new FooBar ();
+ assert (bar.virtual_method () == 14);
+ assert (bar.virtual_interface_method () == 35);
+ assert (foobar.interface_method () == 26);
+ }
+}
+