Re: [Vala] Implement abstract interface method in interface



Hi Jim,

First of all, that looks like a good blog post. I'll have to take the
time to actually read it later today.

Giving this some further thought - (judging from Vala-generated C code)
GObject interfaces are basically just jump tables that are populated in
interface initialization functions, named
[class]_[interface]_interface_init() by Valac. There is no built-in
automatism, at least none that's used by Valac, so it seams to me that
Valac *could* look for missing methods in other interfaces and
automatically generate wrapper functions (or simply set the function
pointers accordingly, assuming the types are right? I'm not sure about this)

It looks like GObject in principle supports the rather ugly case of a
class implementing two interfaces with methods of the same name but with
differing signatures. Vala doesn't handle this case very well as far as
I can see; it certainly doesn't throw an error or print a warning in the
face of such ambiguity - there's no way to specify which method is
supposed to be implemented if it's not obvious, is there? There may be a
need for some more checks  in the compiler, and maybe some additional
annotations.

Cheers
Thomas

On 27/08/12 04:18, Jim Nelson wrote:
Your problem lies here:

interface IBar : IFoo
{
public virtual void bar ()
{
}
}

Because IBar is an interface, it doesn't inherit from IFoo.  Rather, in
Vala that syntax means whatever class implements IBar's interface must
also implement IFoo (or, IFoo is a prerequisite interface for IBar).
 For whatever reason, although interfaces may implement code, in Vala an
interface cannot implement a prerequisite's methods.

I don't know the exact reason why.  I suspect it's a limitation of
GObject and not Vala.

I discuss interfaces on the Yorba blog:
http://blog.yorba.org/jim/2011/11/a-few-of-my-favorite-vala-things-interface.html

-- Jim




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