From: Rico Tzschichholz Date: Mon, 18 Nov 2019 11:49:12 +0000 (+0100) Subject: vala: Improve handling of "void" as generic type X-Git-Tag: 0.47.2~42 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7d772d364fc55ab5944abae8173f9256f14711cd;p=thirdparty%2Fvala.git vala: Improve handling of "void" as generic type Fixes https://gitlab.gnome.org/GNOME/vala/issues/878 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 488ecfbff..5c8a097c2 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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 index 000000000..b44178259 --- /dev/null +++ b/tests/generics/void-type.vala @@ -0,0 +1,35 @@ +class Foo : Object { + public G prop { get; set; } +} + +delegate G FooFunc (G g); + +void foo () { +} + +void main () { + { + var f = new Thread (null, foo); + } + { + Thread f = new Thread (null, foo); + } + { + Thread f = new Thread (null, foo); + } + { + FooFunc f = (FooFunc) foo; + f (null); + } + { + FooFunc f = (FooFunc) foo; + f (null); + } + { + FooFunc f = foo; + f (null); + } + { + var f = new Foo (); + } +} diff --git a/vala/valasemanticanalyzer.vala b/vala/valasemanticanalyzer.vala index 25d0c40dd..41a815742 100644 --- a/vala/valasemanticanalyzer.vala +++ b/vala/valasemanticanalyzer.vala @@ -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)