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 568972 - Generics: Can't return generic array
Generics: Can't return generic array
Status: RESOLVED FIXED
Product: vala
Classification: Core
Component: Arrays
0.5.x
Other All
: Normal normal
: ---
Assigned To: Vala maintainers
Vala maintainers
: 523909 588825 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-01-24 12:12 UTC by Frederik Zipp
Modified: 2010-02-08 07:29 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
support generic arrays (4.38 KB, patch)
2010-01-24 00:35 UTC, Luca Bruno
none Details | Review
support generic arrays (1.65 KB, patch)
2010-01-24 00:37 UTC, Luca Bruno
none Details | Review

Description Frederik Zipp 2009-01-24 12:12:22 UTC
This code doesn't compile:
----------------------------------------------------------
public class Generic<G> : Object {

	public G[] get_array () {
		return new G[10];
	}
}

void main () {
	var generic = new Generic<int> ();
	int[] array = generic.get_array ();
}
----------------------------------------------------------
generic.vala:10.8-10.34: error: Assignment: Cannot convert from `G[]' to `int[]?'
	int[] array = generic.get_array();
	      ^^^^^^^^^^^^^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
Comment 1 Jan Hudec 2009-08-31 11:14:59 UTC
Still reproducible with 0.7.5. And extremely annoying because the Gee.AbstractCollection<G>.to_array() is exactly this case.

Casting to the appropriate array type seems to be a usable workaround.
Comment 2 Jürg Billeter 2009-09-17 11:49:28 UTC
*** Bug 588825 has been marked as a duplicate of this bug. ***
Comment 3 Luca Bruno 2010-01-24 00:35:11 UTC
Created attachment 152120 [details] [review]
support generic arrays

This patch simply expand the generic usage in the array.
This solves other two boring problems:
- say a method void m<T> (T[] arr), the call to m<int> ({"string"}) was allowed, now it's not possible and this is more sane.
- errors won't say "Cannot convert from something to T[]" which was meaningless, but the message contains the actual type.
Comment 4 Luca Bruno 2010-01-24 00:37:28 UTC
Created attachment 152121 [details] [review]
support generic arrays

was wrong patch sorry :S (git commit -a is evil)
Comment 5 Jürg Billeter 2010-01-29 13:00:39 UTC
commit 1788fa5854ac3e393978039851b3a173adc642ec
Author: Luca Bruno <lethalman88@gmail.com>
Date:   Sun Jan 24 01:27:42 2010 +0100

    Fix generic type resolution for arrays of generic types
    
    Arrays of generic types are still only supported for pointer-based
    element types.
    
    Fixes bug 568972.
Comment 6 Jürg Billeter 2010-02-08 07:29:35 UTC
*** Bug 523909 has been marked as a duplicate of this bug. ***