[vala/0.48] codegen: Don't use inferred type for temp-value to access generic property



commit 38a575c661652457332eabc4f5eb60e85325803e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Oct 18 21:08:46 2020 +0200

    codegen: Don't use inferred type for temp-value to access generic property
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1088

 codegen/valaccodememberaccessmodule.vala |  6 +++++-
 tests/Makefile.am                        |  1 +
 tests/generics/property-int-cast.vala    | 12 ++++++++++++
 3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index f46ea9dfd..3199ea24e 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -357,7 +357,11 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                                set_cvalue (expr, ctemp);
                        }
 
-                       expr.target_value.value_type = expr.value_type;
+                       if (prop.get_accessor.value_type is GenericType) {
+                               expr.target_value.value_type = prop.get_accessor.value_type.copy ();
+                       } else {
+                               expr.target_value.value_type = expr.value_type.copy ();
+                       }
                        expr.target_value = store_temp_value (expr.target_value, expr);
                } else if (expr.symbol_reference is LocalVariable) {
                        var local = (LocalVariable) expr.symbol_reference;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b0d553314..3cb7b1865 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -606,6 +606,7 @@ TESTS = \
        generics/parameter-invalid-initializer.test \
        generics/parameter-sizeof-initializer.vala \
        generics/member-dup-destroy.vala \
+       generics/property-int-cast.vala \
        generics/string-literal-comparison.vala \
        generics/type-parameter-properties.vala \
        generics/bug640330.test \
diff --git a/tests/generics/property-int-cast.vala b/tests/generics/property-int-cast.vala
new file mode 100644
index 000000000..69478efd3
--- /dev/null
+++ b/tests/generics/property-int-cast.vala
@@ -0,0 +1,12 @@
+class Foo<G> {
+       public G prop { get; private set; }
+
+       public Foo (G g) {
+               prop = g;
+       }
+}
+
+void main() {
+       var foo = new Foo<int> (23);
+       assert (foo.prop == 23);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]