[vala/staging: 1/2] vala: Allow null-type as intializer for static struct fields
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 1/2] vala: Allow null-type as intializer for static struct fields
- Date: Fri, 30 Nov 2018 17:52:39 +0000 (UTC)
commit 2471bae2612bbb13fe44a97323f59d0907c3399f
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Nov 30 18:43:05 2018 +0100
vala: Allow null-type as intializer for static struct fields
See 1a4a14d5550bb23414c0dc66e8951f4b03bd4137
tests/Makefile.am | 1 +
tests/structs/struct-static-field-initializer.vala | 8 ++++++++
vala/valastruct.vala | 4 ++--
3 files changed, 11 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 02831dc16..a785038b4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -189,6 +189,7 @@ TESTS = \
structs/struct_only.vala \
structs/struct-empty-still.test \
structs/struct-no-gtype.vala \
+ structs/struct-static-field-initializer.vala \
structs/struct-static-field-initializer.test \
structs/struct-static-property-initializer.test \
structs/structs.vala \
diff --git a/tests/structs/struct-static-field-initializer.vala
b/tests/structs/struct-static-field-initializer.vala
new file mode 100644
index 000000000..35a7a1365
--- /dev/null
+++ b/tests/structs/struct-static-field-initializer.vala
@@ -0,0 +1,8 @@
+struct Foo {
+ public int i;
+ public static int foo = 42;
+ public static string? bar = null;
+}
+
+void main () {
+}
diff --git a/vala/valastruct.vala b/vala/valastruct.vala
index 9b5a02a9a..c96632805 100644
--- a/vala/valastruct.vala
+++ b/vala/valastruct.vala
@@ -520,7 +520,7 @@ public class Vala.Struct : TypeSymbol {
if (f.binding == MemberBinding.STATIC && f.initializer != null) {
// for backing property fields a dedicated error will be reported later
- if (!(f in property_fields) && f.variable_type.is_disposable () &&
f.variable_type.value_owned) {
+ if (!(f in property_fields) && !(f.initializer.value_type is NullType) &&
f.variable_type.is_disposable () && f.variable_type.value_owned) {
error = true;
Report.error (f.initializer.source_reference, "Owned static struct
fields can only be initialized in a function or method");
}
@@ -540,7 +540,7 @@ public class Vala.Struct : TypeSymbol {
if (prop.binding == MemberBinding.STATIC) {
unowned Field? field = prop.field;
- if (field != null && field.initializer != null &&
field.variable_type.is_disposable () && field.variable_type.value_owned) {
+ if (field != null && field.initializer != null &&
!(field.initializer.value_type is NullType) && field.variable_type.is_disposable () &&
field.variable_type.value_owned) {
error = true;
Report.error (field.initializer.source_reference, "Owned static
struct properties can only be initialized in a function or method");
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]