[vala/0.40] codegen: Resolve generics in sizeof-expression of parameter initializer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.40] codegen: Resolve generics in sizeof-expression of parameter initializer
- Date: Tue, 9 Apr 2019 13:50:16 +0000 (UTC)
commit d0f084494fefc28838b2806c03cdec33056766ef
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Mon Mar 11 10:31:10 2019 +0100
codegen: Resolve generics in sizeof-expression of parameter initializer
tests/Makefile.am | 1 +
tests/generics/parameter-sizeof-initializer.vala | 28 ++++++++++++++++++++++++
vala/valamethodcall.vala | 9 ++++++++
vala/valaobjectcreationexpression.vala | 9 ++++++++
4 files changed, 47 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 99d45189f..9e78e9b91 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -411,6 +411,7 @@ TESTS = \
asynchronous/yield.vala \
generics/constructor-chain-up.vala \
generics/inference-static-function.vala \
+ generics/parameter-sizeof-initializer.vala \
generics/bug640330.test \
generics/bug640330.vala \
generics/bug694765-1.vala \
diff --git a/tests/generics/parameter-sizeof-initializer.vala
b/tests/generics/parameter-sizeof-initializer.vala
new file mode 100644
index 000000000..1dcc56e1a
--- /dev/null
+++ b/tests/generics/parameter-sizeof-initializer.vala
@@ -0,0 +1,28 @@
+[Compact]
+class Foo<G> {
+ public Foo (ulong real_foo, ulong foo = sizeof (G)) {
+ assert (foo == real_foo);
+ }
+
+ public void bar (ulong real_foo, ulong foo = sizeof (G)) {
+ assert (foo == real_foo);
+ }
+}
+
+void main () {
+ {
+ var garray = new GLib.Array<uint32> ();
+ }
+ {
+ var foo = new Foo<uint32> (sizeof (uint32));
+ foo.bar (4);
+ }
+ {
+ var foo = new Foo<int16> (sizeof (int16));
+ foo.bar (2);
+ }
+ {
+ var foo = new Foo<uint8> (sizeof (uint8));
+ foo.bar (1);
+ }
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index 666b09829..1756dd3dd 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -626,6 +626,15 @@ public class Vala.MethodCall : Expression {
return false;
}
+ //Resolve possible generic-type in SizeofExpression used as parameter default-value
+ foreach (Expression arg in get_argument_list ()) {
+ unowned SizeofExpression sizeof_expr = arg as SizeofExpression;
+ if (sizeof_expr != null && sizeof_expr.type_reference is GenericType) {
+ var sizeof_type = sizeof_expr.type_reference.get_actual_type
(target_object_type, method_type_args, this);
+ replace_expression (arg, new SizeofExpression (sizeof_type,
source_reference));
+ }
+ }
+
/* Check for constructv chain up */
if (base_cm != null && base_cm.is_variadic () && args.size == base_cm.get_parameters ().size)
{
var this_last_arg = args[args.size-1];
diff --git a/vala/valaobjectcreationexpression.vala b/vala/valaobjectcreationexpression.vala
index 0bf086f89..aa387fc37 100644
--- a/vala/valaobjectcreationexpression.vala
+++ b/vala/valaobjectcreationexpression.vala
@@ -489,6 +489,15 @@ public class Vala.ObjectCreationExpression : Expression {
}
}
+ //Resolve possible generic-type in SizeofExpression used as parameter default-value
+ foreach (Expression arg in get_argument_list ()) {
+ unowned SizeofExpression sizeof_expr = arg as SizeofExpression;
+ if (sizeof_expr != null && sizeof_expr.type_reference is GenericType) {
+ var sizeof_type = sizeof_expr.type_reference.get_actual_type (type_reference,
type_reference.get_type_arguments (), this);
+ replace_expression (arg, new SizeofExpression (sizeof_type,
source_reference));
+ }
+ }
+
foreach (MemberInitializer init in get_object_initializer ()) {
context.analyzer.visit_member_initializer (init, type_reference);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]