Should be error when method with [ReturnsModifiedPointer] is called from unowned variable
Submitted by Tal
Link to original bug (#688142)
Description
There should be warning(maybe error) when method with [ReturnsModifiedPointer] is called from unowned variable.
Take a look on GLib.SList. The beginner programmer(me too) can be assign an unowned variable to the list, and remove items, but he don't know it shell update the owned pointer.
Example:
unowned GLib.SList list = given_list; list.remove(data);
Naive programmers can be fooled(like me) that this code are valid, since Vala print no errors neither warning.
Also, what will happen if GLib.SList takes ownership without passing ownership? It should duplicate GLib.SList with "dup_func", but should it duplicate the whole list, or just this item? Same bug can be reproduced when two variables owning same list item.
I think that for fixing up the second bug, you shell remove the auto "dup_func", and let the user decide whether to use g_slist_copy () or g_slist_copy_deep (), by manual Vala methods.
BTW: Same for GLib.List.
Thanks Tal