]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Improve handling of "void" as generic type 7d772d364fc55ab5944abae8173f9256f14711cd
authorRico Tzschichholz <ricotz@ubuntu.com>
Mon, 18 Nov 2019 11:49:12 +0000 (12:49 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 18 Nov 2019 12:07:40 +0000 (13:07 +0100)
Fixes https://gitlab.gnome.org/GNOME/vala/issues/878

codegen/valaccodebasemodule.vala
tests/generics/void-type.vala [new file with mode: 0644]
vala/valasemanticanalyzer.vala

index 488ecfbffcd3a3b673b3505dbe47dfa333fa5379..5c8a097c2be53e519ff3df0a9be2aadb4be745c6 100644 (file)
@@ -2573,6 +2573,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
         * Create a temporary variable and return lvalue access to it
         */
        public TargetValue create_temp_value (DataType type, bool init, CodeNode node_reference, bool? value_owned = null) {
+               if (type is VoidType) {
+                       Report.error (node_reference.source_reference, "internal: 'void' not supported as variable type");
+               }
+
                var local = new LocalVariable (type.copy (), "_tmp%d_".printf (next_temp_var_id++), null, node_reference.source_reference);
                local.init = init;
                if (value_owned != null) {
diff --git a/tests/generics/void-type.vala b/tests/generics/void-type.vala
new file mode 100644 (file)
index 0000000..b441782
--- /dev/null
@@ -0,0 +1,35 @@
+class Foo<G> : Object {
+       public G prop { get; set; }
+}
+
+delegate G FooFunc<G> (G g);
+
+void foo () {
+}
+
+void main () {
+       {
+               var f = new Thread<void> (null, foo);
+       }
+       {
+               Thread f = new Thread<void> (null, foo);
+       }
+       {
+               Thread<void> f = new Thread<void> (null, foo);
+       }
+       {
+               FooFunc f = (FooFunc) foo;
+               f (null);
+       }
+       {
+               FooFunc<void> f = (FooFunc<void>) foo;
+               f (null);
+       }
+       {
+               FooFunc<void> f = foo;
+               f (null);
+       }
+       {
+               var f = new Foo<void> ();
+       }
+}
index 25d0c40ddf535f82f244b734a4d5ca5b6e58eefa..41a815742ef7541b93a95f5985e85e6f06c53e21 100644 (file)
@@ -1344,6 +1344,7 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
        void check_type_argument (DataType type_arg) {
                if (type_arg is GenericType
                    || type_arg is PointerType
+                   || type_arg is VoidType
                    || is_reference_type_argument (type_arg)
                    || is_nullable_value_type_argument (type_arg)
                    || is_signed_integer_type_argument (type_arg)