From: Juerg Billeter Date: Wed, 16 Apr 2008 20:41:50 +0000 (+0000) Subject: Fix base access with virtual interface methods, fixes bug 528457 X-Git-Tag: VALA_0_3_1~55 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5018260dfda88dec45dcd4ce4b7e1a45fa6d3795;p=platform%2Fupstream%2Fvala.git Fix base access with virtual interface methods, fixes bug 528457 2008-04-16 Juerg Billeter * 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 svn path=/trunk/; revision=1247 --- diff --git a/ChangeLog b/ChangeLog index ff26c1c..9eaec2f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2008-04-16 Jürg Billeter + * 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 + * vala/valaparser.vala: improve error handling, fixes bug 528431 2008-04-16 Jürg Billeter diff --git a/gobject/valaccodegenerator.vala b/gobject/valaccodegenerator.vala index 30f2d84..654af43 100644 --- a/gobject/valaccodegenerator.vala +++ b/gobject/valaccodegenerator.vala @@ -3277,10 +3277,10 @@ public class Vala.CCodeGenerator : CodeGenerator { 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)); diff --git a/gobject/valaccodegeneratorinvocationexpression.vala b/gobject/valaccodegeneratorinvocationexpression.vala index 3b20b3d..7ca0d89 100644 --- a/gobject/valaccodegeneratorinvocationexpression.vala +++ b/gobject/valaccodegeneratorinvocationexpression.vala @@ -66,10 +66,10 @@ public class Vala.CCodeGenerator { 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; diff --git a/gobject/valaccodegeneratormemberaccess.vala b/gobject/valaccodegeneratormemberaccess.vala index f90d0e5..018a93c 100644 --- a/gobject/valaccodegeneratormemberaccess.vala +++ b/gobject/valaccodegeneratormemberaccess.vala @@ -29,25 +29,23 @@ public class Vala.CCodeGenerator { 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; @@ -67,6 +65,8 @@ public class Vala.CCodeGenerator { } 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 ()); } diff --git a/tests/classes-methods.vala b/tests/classes-methods.vala index 3226c1c..a0d6483 100644 --- a/tests/classes-methods.vala +++ b/tests/classes-methods.vala @@ -58,6 +58,8 @@ class Maman.SubBar : Bar { test_classes_methods_ref_parameters (); + BaseAccess.test (); + return 0; } } @@ -91,3 +93,54 @@ abstract class Maman.AbstractDerived : AbstractBase { 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); + } +} +