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 605490 - valac drops "?" from return values in generics functions when creating the vapi
valac drops "?" from return values in generics functions when creating the vapi
Status: RESOLVED NOTABUG
Product: vala
Classification: Core
Component: general
0.7.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2009-12-26 16:52 UTC by Julian Andres Klode
Modified: 2010-03-21 16:05 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
writer: don't drop nullable "?" of generic types (805 bytes, patch)
2010-01-26 01:04 UTC, Marc-Andre Lureau
none Details | Review

Description Julian Andres Klode 2009-12-26 16:52:31 UTC
Code like 
 public interface Interface<G> {
     public abstract G? method (string? b);
 }
becomes

 public interface Interface<G> {
     public abstract G method (string? b);
 }

in the VAPI created by valac.
Comment 1 Marc-Andre Lureau 2010-01-26 01:04:04 UTC
Created attachment 152279 [details] [review]
writer: don't drop nullable "?" of generic types

Hopefully fixes bug 605490 :)
Comment 2 Jürg Billeter 2010-03-20 10:59:59 UTC
Dropping the nullable modifier when used with generic types is intentional for the time being. As nullable cannot be nested (e.g., string?? is not supported), using nullable with generic type parameters would only make sense if it was possible to specify that the type parameter must be non-null.

It's possible that Vala will allow non-null type parameters in future versions, however, at the moment, generic classes cannot rely on type parameters being non-null or nullable.
Comment 3 Julian Andres Klode 2010-03-21 15:56:55 UTC
Why not simply:

T=string  => T? = string?
T=string? => T? = string?

And it's really mostly about return values here; because HashMap.get() returns null if it does not find the requested key (and is thus 'T?'). I see no way this could fail (especially if T is already not checked for non-null).
Comment 4 Jürg Billeter 2010-03-21 16:05:48 UTC
There is not enough information available at runtime to do this as 'nullable' doesn't exist in GType. In the case of reference types such as string, it wouldn't need to do anything different, however, in the case of int vs. int? it's not so trivial anymore.