Is the generic type handle issue?
I met some issues like follow:
example one
bool type_gee = typeof(Gee.ArrayList<GLib.Object>) == typeof(Gee.ArrayList<string>);
stdout.printf("Gee type is : %s\n", type_gee.to_string());
// return true
bool type_array = typeof(GLib.Array<GLib.Object>) == typeof(GLib.Array<string>);
stdout.printf("array type is : %s\n", type_array.to_string());
// return true
bool type_vala = typeof(GLib.Object[]) == typeof(string[]);
stdout.printf("vala type is : %s\n", type_vala.to_string());
// return false
I think generic type with different type should be treat as different type.
example two
if (@value.type ().is_a (typeof (string[]))) {
unowned string[] array_value = @value as string[];
if (array_value != null)
{
var array = new Json.Array.sized (array_value.length);
foreach (var item in array_value)
{
array.add_string_element (item);
}
var node = new Json.Node (Json.NodeType.ARRAY);
node.set_array (array);
return node;
}
}
// json-glib serialize code, compiled successfully
int[] obj_array = { 1, 2, 3, 4, 5 };
GLib.Value array_value = GLib.Value(typeof(int[]));
array_value.take_boxed(obj_array);
unowned int[] array_obj = array_value as int[];
if (null != array_obj) {
stdout.printf("object: %d\n", array_obj.length);
}
// compile failed:
// main.vala:51.21-51.40: error: Operation not supported for this type
// var array_obj = array_value as int[];
// ^^^^^^^^^^^^^^^^^^^^
what the difference between them?
unowned string[] array_value = @value as string[]; // ok
unowned int[] array_obj = @array_value as int[]; // error: Operation not supported for this type