Invalid C code is generated (Generics)
Version: e13e0d68
Code:
class Optional<T> {
T? t;
bool is_set;
internal static Optional<T> of(T? t) {
var ret = new Optional<T>();
ret.is_set = true;
ret.t = t;
return ret;
}
internal static Optional<T> empty() {
var ret = new Optional<T>();
ret.is_set = false;
return ret;
}
}
I use this command to compile it: ./valac /tmp/z.vala --library ll
(./valac is the one compiled from source)
Output:
/tmp/z.vala:4.2-4.31: warning: Method `Optional.of' never used
4 | internal static Optional<T> of(T? t) {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/z.vala:10.2-10.34: warning: Method `Optional.empty' never used
10 | internal static Optional<T> empty() {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/tt/bin/z.vala.c: In function ‘optional_of’:
/tmp/tt/bin/z.vala.c:95:32: error: ‘t_type’ undeclared (first use in this function)
95 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~
/tmp/tt/bin/z.vala.c:95:32: note: each undeclared identifier is reported only once for each function it appears in
/tmp/tt/bin/z.vala.c:95:57: error: ‘t_dup_func’ undeclared (first use in this function)
95 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~~~~~
/tmp/tt/bin/z.vala.c:95:86: error: ‘t_destroy_func’ undeclared (first use in this function)
95 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~~~~~~~~~
/tmp/tt/bin/z.vala.c:98:58: warning: implicit declaration of function ‘t_dup_func’ [-Wimplicit-function-declaration]
98 | _tmp1_ = ((t != NULL) && (t_dup_func != NULL)) ? t_dup_func ((gpointer) t) : ((gpointer) t);
| ^~~~~~~~~~
/tmp/tt/bin/z.vala.c:99:88: warning: implicit declaration of function ‘t_destroy_func’ [-Wimplicit-function-declaration]
99 | ((ret->priv->t == NULL) || (t_destroy_func == NULL)) ? NULL : (ret->priv->t = (t_destroy_func (ret->priv->t), NULL));
| ^~~~~~~~~~~~~~
/tmp/tt/bin/z.vala.c: In function ‘optional_empty’:
/tmp/tt/bin/z.vala.c:111:32: error: ‘t_type’ undeclared (first use in this function)
111 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~
/tmp/tt/bin/z.vala.c:111:57: error: ‘t_dup_func’ undeclared (first use in this function)
111 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~~~~~
/tmp/tt/bin/z.vala.c:111:86: error: ‘t_destroy_func’ undeclared (first use in this function)
111 | _tmp0_ = optional_new (t_type, (GBoxedCopyFunc) t_dup_func, (GDestroyNotify) t_destroy_func);
| ^~~~~~~~~~~~~~
In file included from /usr/include/glib-2.0/glib/gthread.h:32,
from /usr/include/glib-2.0/glib/gasyncqueue.h:32,
from /usr/include/glib-2.0/glib.h:32,
from /usr/include/glib-2.0/gobject/gbinding.h:28,
from /usr/include/glib-2.0/glib-object.h:22,
from /tmp/tt/bin/z.vala.c:4:
/tmp/tt/bin/z.vala.c: In function ‘optional_get_type’:
/usr/include/glib-2.0/glib/gatomic.h:113:5: warning: argument 2 of ‘__atomic_load’ discards ‘volatile’ qualifier [-Wincompatible-pointer-types]
113 | __atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
| ^~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gthread.h:260:7: note: in expansion of macro ‘g_atomic_pointer_get’
260 | (!g_atomic_pointer_get (location) && \
| ^~~~~~~~~~~~~~~~~~~~
/tmp/tt/bin/z.vala.c:315:13: note: in expansion of macro ‘g_once_init_enter’
315 | if (g_once_init_enter (&optional_type_id__once)) {
| ^~~~~~~~~~~~~~~~~
error: cc exited with status 256
Compilation failed: 1 error(s), 2 warning(s)
Compiled C: z.c