GNOME Bugzilla – Bug 547362
Interfaces complaining about missing prerequisite when used as variable types.
Last modified: 2008-09-29 16:57:47 UTC
When trying to use interfaces as a common type name for variables or generic classes (eg: List) the valac reports the following error: --- testcase.vala:18.14-18.14: error: missing class prerequisite for interface `IFoo' IFoo i = o; ^ testcase.vala:14.26-14.29: error: missing class prerequisite for interface `IFoo' var list2 = new List<IFoo>(); ^^^^ testcase.vala:18.5-18.8: error: missing class prerequisite for interface `IFoo' IFoo i = o; ^^^^ --- Testcase attached. (Running Vala from SVN r1748)
Created attachment 116393 [details] Testcase demonstrating the problem.
Maybe I can confirm this bug: I'm currently unable to get interfaces working in Vala. When trying to compile the official Tutorial's interface example (see the attachment), I get this error: ------------ pikkio:vala % valac -o interfaces interfaces.vala interfaces2.vala:22.13-22.13: error: missing class prerequisite for interface `ITest' ITest i = t; ^ interfaces2.vala:22.3-22.7: error: missing class prerequisite for interface `ITest' ITest i = t; ^^^^^ Compilation failed: 2 error(s), 0 warning(s) ------------ I don't have adequate Vala knowledge to confirm this, but it looks like the same bug. P.S. I'm using libvala version 0.3.5 on Ubuntu Hardy Backports.
Created attachment 119549 [details] Example code adapted from the official tutorial
Interfaces without class prerequisites can't be used as variables as there is no memory management associated with them. The following example should work fine: public interface ITest : Object { public abstract int data_1 { get; set; } public abstract void function_1 (); } public class Test1 : Object, ITest { public int data_1 { get; set; } public void function_1 () { } } static void main () { Test1 t = new Test1(); t.function_1 (); ITest i = t; i.function_1 (); }
Thanks, I've filed the Bug #554329 against the Vala tutorial, as may lead to this kind of misinterpretation.