GNOME Bugzilla – Bug 605490
valac drops "?" from return values in generics functions when creating the vapi
Last modified: 2010-03-21 16:05:48 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.
Created attachment 152279 [details] [review] writer: don't drop nullable "?" of generic types Hopefully fixes bug 605490 :)
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.
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).
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.