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 786932 - Let the "type-func" override the object's "class" attribute when getting the GType
Let the "type-func" override the object's "class" attribute when getting the ...
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Class: GtkBuilder
3.22.x
Other All
: Normal normal
: ---
Assigned To: GtkBuilder maintainers
GtkBuilder maintainers
Depends on:
Blocks:
 
 
Reported: 2017-08-28 17:28 UTC by Debarshi Ray
Modified: 2017-08-30 19:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkBuilder: Prefer "type-func" over "class" when looking for the GType (3.58 KB, patch)
2017-08-28 17:59 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-08-28 17:28:54 UTC
When both "class" and "type-func" attributes are present, the parser currently ignores the latter in favour of the former. That's odd because "class" is specified as mandatory in the rnc/rng files [1]. So, by its very nature, the "type-func" attribute should be the preferred way to get the GType when both are present.

I think that, depending on the order of the attributes, this was possible before commit 287ba6b94b290.

This has consequences for Vala [2]. For GTK+ template classes, the Vala compiler ensures that all [GtkChild] class members in Vala have a matching XML object with the right type. However, it doesn't know about "type-func". So, if only the "type-func" attribute is used, then it will fail to compile because it won't know about the XML object. See vala/codegen/valagtkmodule.vala

It seems easier to fix this in GtkBuilder than to teach valac to get the type from the "type-func". But I know little about Vala, so I might be wrong.

Chances are pretty high that nobody uses "class" and "type-func" together, because if they did, their "type-func" was being happily ignored so far. So, it will be nice to have this in gtk3 too.

[1] The parser doesn't enforce that (bug 786931).
[2] https://bugs.webkit.org/show_bug.cgi?id=175937#c16
Comment 1 Debarshi Ray 2017-08-28 17:59:24 UTC
Created attachment 358612 [details] [review]
GtkBuilder: Prefer "type-func" over "class" when looking for the GType
Comment 2 Matthias Clasen 2017-08-29 13:19:35 UTC
Review of attachment 358612 [details] [review]:

Makes sense to me. Thanks for adding tests.

Do we have any documentation that needs updating for this change ?
Comment 3 Debarshi Ray 2017-08-29 13:33:49 UTC
Umm... documentation? Doesn't look like it needs updating. The type-func attribute is mentioned in only two places - the GtkBuilder description and GtkBuilderError:GTK_BUILDER_ERROR_INVALID_TYPE_FUNCTION. Both look fine to me.

Thanks for the review.
Comment 4 Debarshi Ray 2017-08-29 13:44:32 UTC
Comment on attachment 358612 [details] [review]
GtkBuilder: Prefer "type-func" over "class" when looking for the GType

Pushed to master and gtk-3-22.