After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 722090 - Use of GLib.return_if_fail in construct {} produces invalid code
Use of GLib.return_if_fail in construct {} produces invalid code
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: Code Generator: GObject
unspecified
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks: 722023
 
 
Reported: 2014-01-13 09:11 UTC by Stef Walter
Modified: 2018-05-22 15:03 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case for this problem (211 bytes, text/plain)
2014-01-13 09:12 UTC, Stef Walter
Details

Description Stef Walter 2014-01-13 09:11:05 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.
Comment 1 Stef Walter 2014-01-13 09:12:27 UTC
Created attachment 266136 [details]
Test case for this problem
Comment 2 Maciej (Matthew) Piechotka 2014-01-13 18:31:42 UTC
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).
Comment 3 Stef Walter 2014-01-13 20:18:55 UTC
Hmmm, if that's the case, what are vala's replacement for these precondition macros? Does vala have vala specific precondition syntax?
Comment 4 Maciej (Matthew) Piechotka 2014-01-13 20:21:57 UTC
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;
}
Comment 5 Maciej (Matthew) Piechotka 2014-01-13 20:22:34 UTC
(In reply to comment #4)
> which arguably mentions return_if_fail and co.

s/arguably//
Comment 6 GNOME Infrastructure Team 2018-05-22 15:03:20 UTC
-- 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.