}
// memory management, implicit casts, and boxing/unboxing
- if (expr.value_type != null) {
+ if (expr is CastExpression && expr.value_type != null && !(expr.value_type is PointerType)
+ && ((CastExpression) expr).inner.value_type is PointerType) {
+ // allow ownership transfer from pointer to non-pointer
+ } else if (expr.value_type != null) {
// FIXME: temporary workaround until the refactoring is complete, not all target_value have a value_type
expr.target_value.value_type = expr.value_type;
expr.target_value = transform_value (expr.target_value, expr.target_type, expr);
structs/struct-initializer-list-nested.vala \
structs/struct-no-gtype.vala \
structs/struct-no-gtype-inherit.vala \
+ structs/struct-pointer-cast.vala \
structs/struct-static-field-initializer.vala \
structs/struct-static-field-initializer-2.test \
structs/struct-static-property-initializer.test \
objects/classes-implicit-implementation.vala \
objects/compact-class.vala \
objects/compact-class-destructor.vala \
+ objects/compact-class-pointer-cast.vala \
objects/compact-class-refcount.vala \
objects/compact-class-custom-ref.vala \
objects/constructor-abstract-public.test \
--- /dev/null
+[Compact]
+class Foo {
+ public int i;
+}
+
+void main () {
+ {
+ Foo foo = (Foo) Slice.alloc (sizeof (int));
+ foo.i = 23;
+ unowned Foo foo_r = foo;
+ assert (foo_r.i == 23);
+ }
+ {
+ Foo* foo_p = Slice.alloc (sizeof (int));
+ foo_p->i = 42;
+ Foo foo = (Foo) foo_p;
+ unowned Foo foo_r = foo;
+ assert (foo_r.i == 42);
+ }
+}
--- /dev/null
+[CCode (has_type_id = false)]
+struct Foo {
+ public int i;
+}
+
+void main () {
+ {
+ Foo? foo = (Foo?) GLib.malloc (sizeof (int));
+ foo.i = 23;
+ unowned Foo? foo_r = foo;
+ assert (foo_r.i == 23);
+ }
+ {
+ Foo* foo_p = GLib.malloc (sizeof (int));
+ foo_p->i = 42;
+ Foo? foo = (Foo?) foo_p;
+ unowned Foo? foo_r = foo;
+ assert (foo_r.i == 42);
+ }
+}