[vala/staging] vala: Non-null initializers are not allowed for owned namespace fields



commit b1ebbd7d49eec615ac0535481997894eec92f554
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Tue Jan 24 14:33:31 2017 +0100

    vala: Non-null initializers are not allowed for owned namespace fields
    
    https://bugzilla.gnome.org/show_bug.cgi?id=777697

 tests/Makefile.am                |    1 +
 tests/basic-types/bug777697.test |    8 ++++++++
 vala/valafield.vala              |    8 ++++++++
 3 files changed, 17 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0db7170..6dc27a6 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -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
index 0000000..0b528ed
--- /dev/null
+++ b/tests/basic-types/bug777697.test
@@ -0,0 +1,8 @@
+Invalid Code
+
+namespace Foo {
+       string bar = "bar";
+}
+
+void main () {
+}
diff --git a/vala/valafield.vala b/vala/valafield.vala
index 8a61665..79d87b1 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -151,6 +151,14 @@ public class Vala.Field : Variable, Lockable {
                                return false;
                        }
 
+                       if (parent_symbol is Namespace && initializer.is_constant () && 
initializer.is_non_null ()) {
+                               if (variable_type.is_disposable () && variable_type.value_owned) {
+                                       error = true;
+                                       Report.error (source_reference, "Invalid assignment from non-null 
initializer to owned field in this context");
+                                       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");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]