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 767718 - Nested namespaces not handled correctly by GIR Writer
Nested namespaces not handled correctly by GIR Writer
Status: RESOLVED OBSOLETE
Product: vala
Classification: Core
Component: GObject Introspection
unspecified
Other All
: Normal critical
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2016-06-16 06:59 UTC by Chris Daley
Modified: 2018-05-22 15:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Fixes nested namespace generation (788 bytes, patch)
2016-06-16 06:59 UTC, Chris Daley
none Details | Review
First Test File (139 bytes, text/x-vala)
2017-03-16 22:30 UTC, Chris Daley
  Details
Second Test File (155 bytes, text/x-vala)
2017-03-16 22:31 UTC, Chris Daley
  Details
Makefile (779 bytes, text/plain)
2017-03-16 22:33 UTC, Chris Daley
  Details
girwriter: GIR.name defines the final name under gir's namespace (940 bytes, patch)
2017-03-17 15:19 UTC, Rico Tzschichholz
none Details | Review

Description Chris Daley 2016-06-16 06:59:13 UTC
Created attachment 329893 [details] [review]
Fixes nested namespace generation

When generating a GIR file for a Vala project, Classes in nested namespaces are handled correctly. I.e.

namespace Valadate.Framework {

    public abstract class TestCase : Object {

    }

}

Is rendered in the GIR file as:

<type name="Valadate.FrameworkTestCase" c:type="ValadateFrameworkTestCase"/>

When this class is used by another project that then generates its own GIR file, these types are rendered incorrectly. i.e.

<type name="Valadate.TestCase" c:type="ValadateFrameworkTestCase"/>

This causes the g-ir-compiler to cause an error.

This bug appears to be caused by the method gi_type_name only returning the actual Class name as defined in the vapi file and the root namespace. The attached patch fixes this bug and allows classes in nested namespaces to be used in other Typelibs.
Comment 2 Chris Daley 2017-03-16 22:30:26 UTC
Created attachment 348130 [details]
First Test File

This is an example abstract class with a nested namespace
Comment 3 Chris Daley 2017-03-16 22:31:23 UTC
Created attachment 348131 [details]
Second Test File

This is the second library which tries to make a subclass of the abstract class defined in the first library
Comment 4 Chris Daley 2017-03-16 22:33:19 UTC
Created attachment 348132 [details]
Makefile

As the error is picked up by the g-ir-compiler, this Makefile attempts to build the typelibs for both libraries and demonstrates the bug
Comment 5 Daniel Espinosa 2017-03-17 02:44:35 UTC
Nested namespaces are not supported by GIR itself, so this is not a Vala's limitation​.

If you are developing a library, avoid nested namespaces and add your namespace to your classes' names.

So Goo.Foo.Bar become Good.FooBar, with same result at C API and makes GIR happy
Comment 6 Chris Daley 2017-03-17 03:25:41 UTC
(In reply to Daniel Espinosa from comment #5)
> Nested namespaces are not supported by GIR itself, so this is not a Vala's
> limitation​.
> 
> If you are developing a library, avoid nested namespaces and add your
> namespace to your classes' names.
> 
> So Goo.Foo.Bar become Good.FooBar, with same result at C API and makes GIR
> happy

This is not a satisfactory resolution to this problem and the report bug should be reopened.

Vala allows you to create multiple nested namespaces and this is easily translated in the Gir files as my patch does by concatenating all the of the nested namespaces. 

Otherwise this is defective behaviour - the language should not allow you to create a construct - i.e nested namespaces and then create incorrect output - the way it currently handles Gir files.

The resolution is to either fix this defective behaviour or remove Vala's ability to generate nested namespaces.
Comment 7 Rico Tzschichholz 2017-03-17 15:19:18 UTC
Created attachment 348185 [details] [review]
girwriter: GIR.name defines the final name under gir's namespace
Comment 8 GNOME Infrastructure Team 2018-05-22 15:36:05 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/541.