GNOME Bugzilla – Bug 722090
Use of GLib.return_if_fail in construct {} produces invalid code
Last modified: 2018-05-22 15:03:20 UTC
The construct { } syntax in vala does not have a return value. However when using GLib.return_if_fail within a construct { } section, the resulting code is placed in an xxx_constructor() function which *does* have a return value. Therefore you get a "Non-void function should return a value" problem. Will attach a test case.
Created attachment 266136 [details] Test case for this problem
I cannot find the reference but IIRC using return_if_fail and similar functions is not recommended as they are treated as normal functions - not a special ones - in Vala (I've posted similar bug some time ago).
Hmmm, if that's the case, what are vala's replacement for these precondition macros? Does vala have vala specific precondition syntax?
Yes. Look at https://wiki.gnome.org/Projects/Vala/Tutorial#Assertions_and_Contract_Programming (which arguably mentions return_if_fail and co.): double method_name(int x, double d) requires (x > 0 && x < 10) requires (d >= 0.0 && d <= 1.0) ensures (result >= 0.0 && result <= 10.0) { return d * x; }
(In reply to comment #4) > which arguably mentions return_if_fail and co. s/arguably//
-- GitLab Migration Automatic Message -- This bug has been migrated to GNOME's GitLab instance and has been closed from further activity. You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.gnome.org/GNOME/vala/issues/426.