[vala/staging: 3/3] vala: Generics value holding struct pointer requires casting on access
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging: 3/3] vala: Generics value holding struct pointer requires casting on access
- Date: Fri, 19 Feb 2021 13:23:34 +0000 (UTC)
commit 23feafb648a4bd1858d131eb98751e4f002d147e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri Feb 19 14:22:20 2021 +0100
vala: Generics value holding struct pointer requires casting on access
Fixes https://gitlab.gnome.org/GNOME/vala/issues/347
tests/Makefile.am | 1 +
tests/generics/value-pointer-type-access.vala | 22 ++++++++++++++++++++++
vala/valamemberaccess.vala | 3 +++
3 files changed, 26 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 612808724..c2a9c7fbe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -670,6 +670,7 @@ TESTS = \
generics/property-int-cast.vala \
generics/string-literal-comparison.vala \
generics/type-parameter-properties.vala \
+ generics/value-pointer-type-access.vala \
generics/bug640330.test \
generics/bug640330.vala \
generics/bug694765-1.vala \
diff --git a/tests/generics/value-pointer-type-access.vala b/tests/generics/value-pointer-type-access.vala
new file mode 100644
index 000000000..d98ca43f9
--- /dev/null
+++ b/tests/generics/value-pointer-type-access.vala
@@ -0,0 +1,22 @@
+class Foo<G> {
+ G g;
+ public void set_g (G data) {
+ g = data;
+ }
+ public G get_g () {
+ return g;
+ }
+}
+
+struct Bar {
+ public int i;
+}
+
+void main () {
+ Bar bar = { 42 };
+ var foo = new Foo<Bar*> ();
+ foo.set_g (&bar);
+
+ assert (foo.get_g ()->i == 42);
+ assert (((Bar*) foo.get_g ())->i == 42);
+}
diff --git a/vala/valamemberaccess.vala b/vala/valamemberaccess.vala
index 368f48c88..d56f7ba93 100644
--- a/vala/valamemberaccess.vala
+++ b/vala/valamemberaccess.vala
@@ -370,6 +370,9 @@ public class Vala.MemberAccess : Expression {
if (inner.value_type is PointerType) {
unowned PointerType? pointer_type = inner.value_type as PointerType;
if (pointer_type != null && pointer_type.base_type is ValueType) {
+ if (inner.formal_value_type is GenericType) {
+ inner = new CastExpression (inner, pointer_type.copy (),
source_reference);
+ }
// transform foo->bar to (*foo).bar
inner = new PointerIndirection (inner, source_reference);
inner.check (context);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]