[Vala] Incorrect C code generated
- From: Dmitry Golovin <dima golovin in>
- To: list vala <vala-list gnome org>
- Subject: [Vala] Incorrect C code generated
- Date: Tue, 22 Mar 2016 22:29:41 +0200
Hello!
Discussed today on the IRC channel, also posting it to the mailing list.
I don't know if it is a vala bug or I am just using things incorrectly.
Here is my code:
struct N {
int i;
}
class ClassA : Object {
public N a { get; set; }
public ClassA(N a) {
this.a = a;
}
}
class ClassB : Object {
public Value b { get; set; }
public ClassB(Value b) {
this.b = b;
}
}
class Main {
static void main() {
var a = new ClassA({ 1 });
var b = new ClassB(a.a);
b.notify["b"].connect((obj, prop) => { a.a = (N)b.b; });
}
}
Here is what C compiler says:
Clang: test.vala.c:413:29: error: cannot take the address of an rvalue of type 'N' (aka 'struct _N')
...&((G_VALUE_HOLDS (&_tmp1_, TYPE_N) && g_value_get_boxed (&_tmp1_)) ? (*((N*) g_value_get_boxed
(&_tmp1_))) : (g_warning ("Invalid GValue unboxing (wrong type or NULL)"), _tmp2_)));
GCC: test.vala.c:413:29: error: lvalue required as unary ‘&’ operand
class_a_set_a (_data1_->a, &((G_VALUE_HOLDS (&_tmp1_, TYPE_N) && g_value_get_boxed (&_tmp1_)) ? (*((N*)
g_value_get_boxed (&_tmp1_))) : (g_warning ("Invalid GValue unboxing (wrong type or NULL)"), _tmp2_)));
This shorter code has similar problem (but it makes much less sense as this cast is impossible):
struct N {
int i;
}
class Main {
static void main() {
N n = { 42 };
Value v = n;
int i = (int)((N)v);
print("%d\n", i);
}
}
In this code cast from Value to my struct works fine:
struct N {
int i;
}
class Main {
static void main() {
N n = { 42 };
Value v = n;
n = (N)v;
print("%d %d\n", n.i, ((N)v).i);
}
}
Could you please make any suggestions on how do I fix the code from the very first examples, if it is
terribly wrong?
While writing this message, also found this bug: https://bugzilla.gnome.org/show_bug.cgi?id=764041
Regards,
Dmitry
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]