[vala/staging] vala: Improve handling of "void" as generic type
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Improve handling of "void" as generic type
- Date: Mon, 18 Nov 2019 12:09:26 +0000 (UTC)
commit 7d772d364fc55ab5944abae8173f9256f14711cd
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Nov 18 12:49:12 2019 +0100
vala: Improve handling of "void" as generic type
Fixes https://gitlab.gnome.org/GNOME/vala/issues/878
codegen/valaccodebasemodule.vala | 4 ++++
tests/generics/void-type.vala | 35 +++++++++++++++++++++++++++++++++++
vala/valasemanticanalyzer.vala | 1 +
3 files changed, 40 insertions(+)
---
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)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]