[vala/0.34] vala: Non-null initializers are not allowed for owned namespace fields
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.34] vala: Non-null initializers are not allowed for owned namespace fields
- Date: Thu, 16 Mar 2017 11:55:14 +0000 (UTC)
commit 71cb2acdb09d9d662e7c148d39859ca082e24a14
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 a5f52e0..a58235b 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -42,6 +42,7 @@ TESTS = \
basic-types/bug731017.vala \
basic-types/bug761307.vala \
basic-types/bug771626.test \
+ basic-types/bug777697.test \
namespaces.vala \
methods/lambda.vala \
methods/closures.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 e54cbd1..4a1e5ae 100644
--- a/vala/valafield.vala
+++ b/vala/valafield.vala
@@ -159,6 +159,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, "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");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]