[vala/staging] codegen: Don't add errornous cast for unknown type_symbol
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Don't add errornous cast for unknown type_symbol
- Date: Fri, 7 May 2021 11:59:45 +0000 (UTC)
commit 86e992f774bd706e386acd00210548e493b268ef
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Fri May 7 13:46:28 2021 +0200
codegen: Don't add errornous cast for unknown type_symbol
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 | 2 +-
tests/generics/reference-transfer.vala | 14 ++++++++++++--
2 files changed, 13 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 8f74e0d34..88a3d74c9 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -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));
}
}
diff --git a/tests/generics/reference-transfer.vala b/tests/generics/reference-transfer.vala
index da2c1e305..5dc7a666f 100644
--- a/tests/generics/reference-transfer.vala
+++ b/tests/generics/reference-transfer.vala
@@ -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");
+ }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]