[vala/staging] parser: Improve handling of nullable VarType in with-statement
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] parser: Improve handling of nullable VarType in with-statement
- Date: Tue, 25 Jan 2022 17:14:35 +0000 (UTC)
commit 6a8e2795d313b98bc60ff3956b911ff7297451fe
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Tue Jan 25 18:10:49 2022 +0100
parser: Improve handling of nullable VarType in with-statement
tests/nullability/var-type.c-expected | 7 +++++++
tests/nullability/var-type.vala | 5 +++++
tests/parser/var-type-nullable.c-expected | 15 +++++++++++++++
tests/parser/var-type-nullable.vala | 8 ++++++++
vala/valaparser.vala | 9 +++++++--
5 files changed, 42 insertions(+), 2 deletions(-)
---
diff --git a/tests/nullability/var-type.c-expected b/tests/nullability/var-type.c-expected
index 9d0f55e35..10be13b51 100644
--- a/tests/nullability/var-type.c-expected
+++ b/tests/nullability/var-type.c-expected
@@ -56,6 +56,13 @@ _vala_main (void)
foo_collection = (_vala_array_free (foo_collection, foo_collection_length1,
(GDestroyNotify) g_free), NULL);
}
}
+ {
+ {
+ const gchar* foo = NULL;
+ foo = "foo";
+ _vala_assert (foo != NULL, "foo != null");
+ }
+ }
}
int
diff --git a/tests/nullability/var-type.vala b/tests/nullability/var-type.vala
index 3497d8606..42442b18e 100644
--- a/tests/nullability/var-type.vala
+++ b/tests/nullability/var-type.vala
@@ -8,4 +8,9 @@ void main () {
assert (foo != null);
}
}
+ {
+ with (unowned var? foo = "foo") {
+ assert (foo != null);
+ }
+ }
}
diff --git a/tests/parser/var-type-nullable.c-expected b/tests/parser/var-type-nullable.c-expected
index 5f86e3499..84096141e 100644
--- a/tests/parser/var-type-nullable.c-expected
+++ b/tests/parser/var-type-nullable.c-expected
@@ -82,6 +82,21 @@ _vala_main (void)
foo_collection = (_vala_array_free (foo_collection, foo_collection_length1,
(GDestroyNotify) g_free), NULL);
}
}
+ {
+ {
+ gchar* foo = NULL;
+ gchar* _tmp8_;
+ _tmp8_ = g_strdup ("foo");
+ foo = _tmp8_;
+ _g_free0 (foo);
+ }
+ }
+ {
+ {
+ const gchar* foo = NULL;
+ foo = "foo";
+ }
+ }
}
int
diff --git a/tests/parser/var-type-nullable.vala b/tests/parser/var-type-nullable.vala
index fb3256970..0600a0952 100644
--- a/tests/parser/var-type-nullable.vala
+++ b/tests/parser/var-type-nullable.vala
@@ -13,4 +13,12 @@ void main () {
foreach (unowned var? foo in new string[] { "foo", "bar" }) {
}
}
+ {
+ with (var? foo = "foo") {
+ }
+ }
+ {
+ with (unowned var? foo = "foo") {
+ }
+ }
}
diff --git a/vala/valaparser.vala b/vala/valaparser.vala
index ebb914da1..1e84c8bfa 100644
--- a/vala/valaparser.vala
+++ b/vala/valaparser.vala
@@ -2541,8 +2541,13 @@ public class Vala.Parser : CodeVisitor {
LocalVariable? local = null;
// Try "with (expr)"
- Expression expr = parse_expression ();
- if (!accept (TokenType.CLOSE_PARENS)) {
+ Expression expr;
+ try {
+ expr = parse_expression ();
+ } catch {
+ expr = null;
+ }
+ if (expr == null || !accept (TokenType.CLOSE_PARENS)) {
// Try "with (var identifier = expr)"
rollback (expr_or_decl);
DataType variable_type;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]