]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
Add ownership-checks for field initializers
authorFlorian Brosch <flo.brosch@gmail.com>
Thu, 18 Sep 2014 00:53:29 +0000 (02:53 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Wed, 1 Oct 2014 20:38:05 +0000 (22:38 +0200)
vala/valafield.vala

index e6429a192c0eb2ca0a9b9630f99e42dc0b67ae1d..5eb84dedb35706abc898cf9372d29f391adb469a 100644 (file)
@@ -143,6 +143,16 @@ public class Vala.Field : Variable, Lockable {
                                return false;
                        }
 
+                       if (initializer.value_type.is_disposable ()) {
+                               /* rhs transfers ownership of the expression */
+                               if (!(variable_type is PointerType) && !variable_type.value_owned) {
+                                       /* lhs doesn't own the value */
+                                       error = true;
+                                       Report.error (source_reference, "Invalid assignment from owned expression to unowned variable");
+                                       return false;
+                               }
+                       }
+
                        if (parent_symbol is Namespace && !initializer.is_constant ()) {
                                error = true;
                                Report.error (source_reference, "Non-constant field initializerS not supported in this context");