diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-04-15 16:49:14 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2021-04-15 16:49:14 +0200 |
commit | 4f2ef8fa3c391451f0ea788ad6e8ea6c15ef0430 (patch) | |
tree | dde47cb1131ccfe2c48f50d90106df354bc12c56 /vala/valaforeachstatement.vala | |
parent | eb7dc13c0d4cf66c153852513c69c5caccec5a7d (diff) | |
download | vala-4f2ef8fa3c391451f0ea788ad6e8ea6c15ef0430.tar.gz |
Support explicit nullable var-type declarations
var? foo = "foo";
unowned var? bar = "bar";
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1146
Diffstat (limited to 'vala/valaforeachstatement.vala')
-rw-r--r-- | vala/valaforeachstatement.vala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/vala/valaforeachstatement.vala b/vala/valaforeachstatement.vala index bea6c4e93..0af0b52ba 100644 --- a/vala/valaforeachstatement.vala +++ b/vala/valaforeachstatement.vala @@ -336,12 +336,16 @@ public class Vala.ForeachStatement : Block { // analyze element type if (type_reference is VarType) { // var type + bool nullable = type_reference.nullable; bool value_owned = type_reference.value_owned; type_reference = element_type.copy (); // FIXME Only follows "unowned var" otherwise inherit ownership of element-type if (!value_owned) { type_reference.value_owned = false; } + if (nullable) { + type_reference.nullable = true; + } } else if (!element_type.compatible (type_reference)) { error = true; Report.error (source_reference, "Foreach: Cannot convert from `%s' to `%s'", element_type.to_string (), type_reference.to_string ()); @@ -359,12 +363,16 @@ public class Vala.ForeachStatement : Block { // analyze element type if (type_reference is VarType) { // var type + bool nullable = type_reference.nullable; bool value_owned = type_reference.value_owned; type_reference = element_type.copy (); // FIXME Only follows "unowned var" otherwise inherit ownership of element-type if (!value_owned) { type_reference.value_owned = false; } + if (nullable) { + type_reference.nullable = true; + } } else if (!element_type.compatible (type_reference)) { error = true; Report.error (source_reference, "Foreach: Cannot convert from `%s' to `%s'", element_type.to_string (), type_reference.to_string ()); |