diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-18 12:49:12 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2019-11-18 13:07:40 +0100 |
commit | 7d772d364fc55ab5944abae8173f9256f14711cd (patch) | |
tree | 1b718c4a039a7bfbc45a6ab84298b7abe7077fd8 | |
parent | b5442af426ac432fbf0a3a4f3c341952eecf5a41 (diff) | |
download | vala-7d772d364fc55ab5944abae8173f9256f14711cd.tar.gz |
vala: Improve handling of "void" as generic type
Fixes https://gitlab.gnome.org/GNOME/vala/issues/878
-rw-r--r-- | codegen/valaccodebasemodule.vala | 4 | ||||
-rw-r--r-- | tests/generics/void-type.vala | 35 | ||||
-rw-r--r-- | vala/valasemanticanalyzer.vala | 1 |
3 files changed, 40 insertions, 0 deletions
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<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> (); + } +} 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) |