]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Non-null initializers are not allowed for owned namespace fields
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 24 Jan 2017 13:33:31 +0000 (14:33 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Sun, 12 Feb 2017 18:44:18 +0000 (19:44 +0100)
https://bugzilla.gnome.org/show_bug.cgi?id=777697

tests/Makefile.am
tests/basic-types/bug777697.test [new file with mode: 0644]
vala/valafield.vala

index cd8aa0859e18248823e4371242e4737667d3df07..76fb108b78445d5ef8632da70fe83c568170a993 100644 (file)
@@ -43,6 +43,7 @@ TESTS = \
        basic-types/bug756376.vala \
        basic-types/bug761307.vala \
        basic-types/bug771626.test \
+       basic-types/bug777697.test \
        pointers/bug590641.vala \
        namespaces.vala \
        methods/lambda.vala \
diff --git a/tests/basic-types/bug777697.test b/tests/basic-types/bug777697.test
new file mode 100644 (file)
index 0000000..0b528ed
--- /dev/null
@@ -0,0 +1,8 @@
+Invalid Code
+
+namespace Foo {
+       string bar = "bar";
+}
+
+void main () {
+}
index 8a61665824c4bb7adf43f2b77b50c1fdef5b3c54..3af9433d66ed87cd3a8f8379784d2ead26108f6e 100644 (file)
@@ -151,6 +151,14 @@ public class Vala.Field : Variable, Lockable {
                                return false;
                        }
 
+                       if (parent_symbol is Namespace && initializer.is_constant ()) {
+                               if ((variable_type.nullable || nitializer.is_non_null ()) && (variable_type.value_owned || variable_type.is_disposable ())) {
+                                       error = true;
+                                       Report.error (source_reference, "Owned namespace fields can only be initialized in a function or method");
+                                       return false;
+                               }
+                       }
+
                        if (binding == MemberBinding.STATIC && parent_symbol is Class && ((Class)parent_symbol).is_compact && !initializer.is_constant ()) {
                                error = true;
                                Report.error (source_reference, "Static fields in compact classes cannot have non-constant initializers");