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 585847 - The length property of array properties is not correctly retrieved.
The length property of array properties is not correctly retrieved.
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Objects
0.7.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 593859 605627 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-06-15 13:09 UTC by Julien Fontanet
Modified: 2010-10-14 14:44 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Julien Fontanet 2009-06-15 13:09:42 UTC
class AClass {
	private int[] _array = new int[] {1, 2, 3};

	public int[] array {
		get {return this._array;}
	}
}
var a = new AClass ();
stdout.printf ("%d\n", a.array.length);

"3" should be print on the screen, however "0" is displayed.

Here is the C code:
AClass* a;
gint _tmp0_;
a = aclass_new ();
fprintf (stdout, "%d\n", _tmp0_);
Comment 1 Jürg Billeter 2009-08-16 21:09:11 UTC
Confirming.
Comment 2 Jürg Billeter 2009-09-15 17:13:02 UTC
*** Bug 593859 has been marked as a duplicate of this bug. ***
Comment 3 Michael 'Mickey' Lauer 2009-10-16 23:10:10 UTC
The foreach statement seems to get this right, hence for your viewing pleasure here's the ugly workaround:

var length = 0;
foreach ( var element in array )
{
    length++;
}
Comment 4 Jürg Billeter 2009-10-17 19:43:05 UTC
There is an easier workaround:

	var arr = a.array;
	stdout.printf ("%d\n", arr.length);
Comment 5 Jürg Billeter 2010-01-08 20:37:31 UTC
*** Bug 605627 has been marked as a duplicate of this bug. ***
Comment 6 Jürg Billeter 2010-10-14 14:44:25 UTC
commit 5226feafef569a54d88c71468edf03eb99345ff2
Author: Jürg Billeter <j@bitron.ch>
Date:   Thu Oct 14 16:43:17 2010 +0200

    codegen: Use separate C statements for property access
    
    Fixes bug 585847.