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 664630 - Default Iterator for Gee HashMap seems to be broken.
Default Iterator for Gee HashMap seems to be broken.
Status: RESOLVED DUPLICATE of bug 645850
Product: vala
Classification: Core
Component: Semantic Analyzer
0.14.x
Other Linux
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
Depends on:
Blocks:
 
 
Reported: 2011-11-23 11:21 UTC by Paul Jakma
Modified: 2013-05-11 19:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Test case with comments and output to illustrate the problem (2.23 KB, text/x-vala)
2011-11-23 11:21 UTC, Paul Jakma
Details

Description Paul Jakma 2011-11-23 11:21:23 UTC
Created attachment 201986 [details]
Test case with comments and output to illustrate the problem

The default iterator for instances of HashMap seems to be broken. I.e.:

var foos = new Gee.HashMap<int, Foo> (keyfunc, eqfunc);

foreach (var f in foos)
 <do stuff with f>

Seems to result in an iterator over the value type of foos, rather than Gee.Iterable<Gee.Map.Entry<K,V>> - which is what the VAPI for AbstractMap in Gee 0.6.1 (Fedora package libgee-0.6.1-3.fc16.x86_64) seems to suggest should be the type.

Also, even if this were a problem in my understanding and Foo is the correct type and the iterator is intended to be over the values, the iterator is still functionally broken: it does not return all the values, instead it returns a nil entry.
Comment 1 Maciej (Matthew) Piechotka 2011-11-23 13:47:08 UTC
(In reply to comment #0)
> Created an attachment (id=201986) [details]
> Test case with comments and output to illustrate the problem
> 
> The default iterator for instances of HashMap seems to be broken. I.e.:
> 
> var foos = new Gee.HashMap<int, Foo> (keyfunc, eqfunc);
> 
> foreach (var f in foos)
>  <do stuff with f>
> 
> Seems to result in an iterator over the value type of foos, rather than
> Gee.Iterable<Gee.Map.Entry<K,V>> - which is what the VAPI for AbstractMap in
> Gee 0.6.1 (Fedora package libgee-0.6.1-3.fc16.x86_64) seems to suggest should
> be the type.
> 

What's the generated code?

> Also, even if this were a problem in my understanding and Foo is the correct
> type and the iterator is intended to be over the values, the iterator is still
> functionally broken: it does not return all the values, instead it returns a
> nil entry.

It is definitly bug. Could you post separate bug for libgee (in this way I won't forgot to check it, also it probably needs to be fixed separately so it will help bookkeeping) if it is not fixed in 0.6.3 version (0.6.2 and 0.6.3 are bugfix releases).
Comment 2 Paul Jakma 2011-12-01 16:58:33 UTC
Which part of this bug is libgee, so I can create a sensible bug for that? :)
Comment 3 Maciej (Matthew) Piechotka 2011-12-01 17:01:01 UTC
(In reply to comment #2)
> Which part of this bug is libgee, so I can create a sensible bug for that? :)

I would say: "the iterator is still functionally broken: it does not return all the values, instead it returns a nil entry.". It might have root cause from Vala problem but at least it sounds like it might have something in common with libgee itself.
Comment 4 Simon Werbeck 2012-11-02 00:57:33 UTC
As I see it, this is because Gee.Map also supports 'get/size' which takes precedence over the 'iterator' method.
foreach (foo in foos) {
	...
}

using get/size, it will iterate over the range 0..size even if e.g. 0 is not a key in the map.
A solution would be to introduce a new attribute which disables 'get/size' iteration. Maybe even something like this:

	[NoSyntaxSupport]
	public V get (V value) {
		...
	}
Comment 5 Maciej (Matthew) Piechotka 2013-05-11 19:18:35 UTC

*** This bug has been marked as a duplicate of bug 645850 ***