GNOME Bugzilla – Bug 614294
Mismatching error signature in async virtual function leads to invalid C code
Last modified: 2018-02-04 10:06:12 UTC
Please consider the following test case: ======================================= public enum UsageResourcePolicy { FOO, BAR } public errordomain MyError { FOO, BAR } public interface IResource : Object { public abstract async void setPolicy( UsageResourcePolicy policy ) throws MyError, DBus.Error; } public class Resource : IResource, Object { public virtual async void setPolicy( UsageResourcePolicy policy ) { message( "yo" ); } } async void runAsync() { var r = new Resource(); yield r.setPolicy( UsageResourcePolicy.FOO ); } void main() { runAsync(); } ======================================= mickey@andromeda:/tmp$ valac --save-temps --pkg gio-2.0 --pkg dbus-glib-1 async.vala /tmp/async.c: In function ‘resource_iresource_interface_init’: /tmp/async.c:243: warning: assignment from incompatible pointer type /tmp/async.c:244: warning: assignment from incompatible pointer type /tmp/async.c: In function ‘runAsync_co’: /tmp/async.c:312: error: too few arguments to function ‘resource_setPolicy_finish’ error: cc exited with status 256 Compilation failed: 1 error(s), 0 warning(s)
Vala should probably refuse to compile this and emit an error.
It seems that the error parameter is missing in the code. why should vala refuse to compile this code?
Because Vala should try very hard to never emit C code that doesn't compile. It's breaking the semantic level of abstraction, if you force the user finding out what's wrong in the C code to fix it in Vala code.
In this case vala should be smarter. Frmo a semantic view point, it's fine to have no throws in the overridden method as it's stronger. In this case the C code should still emit the error parameter, and set it to NULL.
Created attachment 367514 [details] [review] codegen: Method needs to throw error if their base method does
Making this fatal causes more fuzz than I expected, so going to infer error-types from base-method would be smarter. http://paldo.org:8010/builders/vala-staging/builds/394
Created attachment 367523 [details] [review] codegen: Infer error parameter from abstract/virtual method implementations
Attachment 367523 [details] pushed as 527dac8 - codegen: Infer error parameter from abstract/virtual method implementations