closure_new.add_argument (new CCodeCastExpression (cexpr, "GCallback"));
closure_new.add_argument (delegate_target);
closure_new.add_argument (new CCodeCastExpression (delegate_target_destroy_notify, "GClosureNotify"));
- cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeConstant ("NULL")), new CCodeConstant ("NULL"), closure_new);
+ //TODO Use get_non_null (arg.target_value)
+ if (arg.is_non_null ()) {
+ cexpr = closure_new;
+ } else {
+ cexpr = new CCodeConditionalExpression (new CCodeBinaryExpression (CCodeBinaryOperator.EQUALITY, cexpr, new CCodeConstant ("NULL")), new CCodeConstant ("NULL"), closure_new);
+ }
} else {
// Override previously given target/destroy only if it was NULL
// TODO https://gitlab.gnome.org/GNOME/vala/issues/59
var foo = new Foo ();
var bar = new Bar ();
+ BindingTransformFunc transform_to_func = (BindingTransformFunc) to_int;
+
foo.bind_property ("foo", bar, "bar", BindingFlags.BIDIRECTIONAL,
- (BindingTransformFunc) to_int, (BindingTransformFunc) to_string);
+ transform_to_func, (BindingTransformFunc) to_string);
foo.foo = "42";
assert (bar.bar == 42);
}
}
+ public override bool is_non_null () {
+ return is_non_null_cast || (!is_silent_cast && inner.is_non_null ());
+ }
+
public override void get_error_types (Collection<DataType> collection, SourceReference? source_reference = null) {
inner.get_error_types (collection, source_reference);
}
public override bool is_non_null () {
unowned Constant? c = symbol_reference as Constant;
unowned LocalVariable? l = symbol_reference as LocalVariable;
+ unowned Method? m = symbol_reference as Method;
if (c != null) {
return (c is EnumValue || !c.type_reference.nullable);
} else if (l != null) {
return (l.variable_type is ArrayType && ((ArrayType) l.variable_type).inline_allocated);
+ } else if (m != null) {
+ return (m.binding == MemberBinding.STATIC || prototype_access);
} else {
return false;
}