]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
parser: Improve handling of nullable VarType in with-statement
authorRico Tzschichholz <ricotz@ubuntu.com>
Tue, 25 Jan 2022 17:10:49 +0000 (18:10 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Tue, 25 Jan 2022 17:12:56 +0000 (18:12 +0100)
tests/nullability/var-type.c-expected
tests/nullability/var-type.vala
tests/parser/var-type-nullable.c-expected
tests/parser/var-type-nullable.vala
vala/valaparser.vala

index 9d0f55e35803fbb0f10b6c9eb9d81563b539823e..10be13b515f099796c5f61873ee65ddcc4522974 100644 (file)
@@ -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
index 3497d8606e44c394091b7b8ea34f36d0ed32521e..42442b18ee9d97962f833cd36a4feee1358e333f 100644 (file)
@@ -8,4 +8,9 @@ void main () {
                        assert (foo != null);
                }
        }
+       {
+               with (unowned var? foo = "foo") {
+                       assert (foo != null);
+               }
+       }
 }
index 5f86e349995e06c69dd9ddeefc82797c9d8eaa13..84096141ec23bee7662726de17009cb1d6477dec 100644 (file)
@@ -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
index fb3256970267d77204f820b3be598c7a49b21456..0600a095292bc94ce766dd68572e71de137b1395 100644 (file)
@@ -13,4 +13,12 @@ void main () {
                foreach (unowned var? foo in new string[] { "foo", "bar" }) {
                }
        }
+       {
+               with (var? foo = "foo") {
+               }
+       }
+       {
+               with (unowned var? foo = "foo") {
+               }
+       }
 }
index ebb914da1649e91c4c2a013f9e7efdb0c3b9f23e..1e84c8bfa99a348ede19fea9280eb260ca3736e1 100644 (file)
@@ -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;