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 791283 - Codegen attempts to wrap GDestroyNotify parameters local to the constructor scope
Codegen attempts to wrap GDestroyNotify parameters local to the constructor s...
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Generics
0.39.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 791060 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2017-12-05 20:24 UTC by bob
Modified: 2017-12-07 08:33 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
0001-tests-add-destroy-wrapper-test.patch (1.32 KB, patch)
2017-12-05 20:24 UTC, bob
none Details | Review
0002-codegen-don-t-wrap-generic-GDestroyNotify.patch (1.38 KB, patch)
2017-12-05 20:25 UTC, bob
none Details | Review
codegen: Don't create null-safe destroy-wrapper for GenericType (2.03 KB, patch)
2017-12-06 23:08 UTC, Rico Tzschichholz
committed Details | Review

Description bob 2017-12-05 20:24:59 UTC
Created attachment 365062 [details] [review]
0001-tests-add-destroy-wrapper-test.patch

Patches incoming
Comment 1 bob 2017-12-05 20:25:21 UTC
Created attachment 365063 [details] [review]
0002-codegen-don-t-wrap-generic-GDestroyNotify.patch
Comment 2 Rico Tzschichholz 2017-12-06 10:40:09 UTC
As reference for the reason to create null-safe destroy-functions in this situation: https://git.gnome.org/browse/vala/commit/?id=f06c7c67cc1c2f626b06a676583f3716d3c155ae
Comment 3 Al Thomas 2017-12-06 12:01:52 UTC
Let's be specific - the example is attempting to create a new GenericArray in the constructor for the object. I think a work around is probably:

class Test<T> {
    public GenericArray<T> inner = new GenericArray<T> ();

    public Test () {
        //inner = new GenericArray<T> ();
    }
}

void main () {
    var test = new Test<string> ();
}

but it doesn't solve the bug. At the level of Vala syntax this is a similar problem to https://bugzilla.gnome.org/show_bug.cgi?id=791060
Comment 4 Daniel Espinosa 2017-12-06 13:14:35 UTC
(In reply to Al Thomas from comment #3)
> Let's be specific - the example is attempting to create a new GenericArray
> in the constructor for the object. I think a work around is probably:
> 
> class Test<T> {
>     public GenericArray<T> inner = new GenericArray<T> ();
> 
>     public Test () {
>         //inner = new GenericArray<T> ();
>     }
> }
> 
> void main () {
>     var test = new Test<string> ();
> }
> 
> but it doesn't solve the bug. At the level of Vala syntax this is a similar
> problem to https://bugzilla.gnome.org/show_bug.cgi?id=791060

If the programmer doesn't want to construct a generic class, may be because she/he doesn't want to expose Vala generic API, you can extend above class as:

public class Bar : Test<int> {}

So your users will have a non generic int implemented class.
Comment 5 Al Thomas 2017-12-06 16:16:27 UTC
(In reply to Daniel Espinosa from comment #4)
> If the programmer doesn't want to construct a generic class, may be because
> she/he doesn't want to expose Vala generic API, you can extend above class
> as:
> 
> public class Bar : Test<int> {}

While that may be a useful programming tip, I'm not sure it relates to this bug. I'm still getting the error reported originally when I compile:

class Test<T> {
    public GenericArray<T> inner;

    public Test () {
        inner = new GenericArray<T> ();
    }
}

class Bar : Test<string> {}

void main () {
    var test = new Bar ();
}

However T is available in the scope of the class:

class Test<T> {
    public GenericArray<T> inner;

    public Test () {
        print (@"$(typeof(T).name())\n");
        //inner = new GenericArray<T> ();
    }

    public void print_type () {
        print (@"$(typeof(T).name())\n");
    }
}

void main () {
    var test = new Test<string> ();
    test.print_type ();
}

produces:

gchararray
gchararray
Comment 6 Rico Tzschichholz 2017-12-06 23:07:16 UTC
*** Bug 791060 has been marked as a duplicate of this bug. ***
Comment 7 Rico Tzschichholz 2017-12-06 23:08:31 UTC
Created attachment 365165 [details] [review]
codegen: Don't create null-safe destroy-wrapper for GenericType
Comment 8 Rico Tzschichholz 2017-12-07 08:33:15 UTC
Attachment 365165 [details] pushed as ac0dbad - codegen: Don't create null-safe destroy-wrapper for GenericType