]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't add errornous cast for unknown type_symbol
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 7 May 2021 11:46:28 +0000 (13:46 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 7 May 2021 11:52:48 +0000 (13:52 +0200)
This causes invalid C code for reference transfer of GenericType.

Regression of 7ae2f115a702439bd94bf09867b38019f39d010f

Fixes https://gitlab.gnome.org/GNOME/vala/issues/1180

codegen/valaccodememberaccessmodule.vala
tests/generics/reference-transfer.vala

index 8f74e0d34a3d0dd1dad76fe41cc368acdd09b430..88a3d74c9e0f56cbda0e8a8ec55944729c65ee3a 100644 (file)
@@ -413,7 +413,7 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
                // Add cast for narrowed type access of variables if needed
                if (expr.symbol_reference is Variable) {
                        unowned GLibValue cvalue = (GLibValue) expr.target_value;
-                       if (cvalue.value_type.type_symbol != expr.value_type.type_symbol) {
+                       if (cvalue.value_type.type_symbol != null && cvalue.value_type.type_symbol != expr.value_type.type_symbol) {
                                cvalue.cvalue = new CCodeCastExpression (cvalue.cvalue, get_ccode_name (expr.value_type));
                        }
                }
index da2c1e3058e6a87efb97bc1aea034b248d87f074..5dc7a666f0323113b1e259d6ef97b8cc02693016 100644 (file)
@@ -19,6 +19,16 @@ void foo<G> (owned G g) {
 }
 
 void main () {
-       foo<string> ("foo");
-       bar<string> (new Bar<string> ("bar"));
+       {
+               foo<string> ("foo");
+       }
+       {
+               bar<string> (new Bar<string> ("bar"));
+       }
+       {
+               var bar = new Bar<string> ("bar");
+               var t = (owned) bar.g;
+               assert (bar.g == null);
+               assert (t == "bar");
+       }
 }