[vala/0.50] codegen: Correctly retrieve symbol_reference of nested cast expressions
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.50] codegen: Correctly retrieve symbol_reference of nested cast expressions
- Date: Sun, 28 Feb 2021 08:58:22 +0000 (UTC)
commit 1cfad14c04faed13b88bc00c4ee27210754b56a0
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sun Feb 7 08:57:39 2021 +0100
codegen: Correctly retrieve symbol_reference of nested cast expressions
Regression of 63551acaf0d83fac8b50904c2759c1098fbfaa71
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1134
codegen/valaccodebasemodule.vala | 7 ++++++-
tests/generics/integer-type-cast.vala | 9 +++++++++
2 files changed, 15 insertions(+), 1 deletion(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index c2127094d..171c6f0fb 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5397,7 +5397,12 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
var innercexpr = get_cvalue (expr.inner);
if (expr.type_reference is ValueType && !expr.type_reference.nullable &&
expr.inner.value_type is ValueType && expr.inner.value_type.nullable) {
- if (!(expr.inner.symbol_reference is Variable)) {
+ // handle nested cast expressions
+ unowned Expression? inner_expr = expr.inner;
+ while (inner_expr is CastExpression) {
+ inner_expr = ((CastExpression) inner_expr).inner;
+ }
+ if (!(inner_expr.symbol_reference is Variable)) {
// heap allocated struct leaked, destroy it
var value = new GLibValue (new PointerType (new VoidType ()), innercexpr);
temp_ref_values.insert (0, value);
diff --git a/tests/generics/integer-type-cast.vala b/tests/generics/integer-type-cast.vala
index 4d7ea8ba6..5e3855aa5 100644
--- a/tests/generics/integer-type-cast.vala
+++ b/tests/generics/integer-type-cast.vala
@@ -3,7 +3,16 @@ void foo<G,T> (G g, T t) {
assert ((uint64?) t == uint64.MAX);
}
+void bar<G,T> (G g, T t) {
+ assert ((int?) g == int.MIN);
+ assert ((uint?) t == uint.MAX);
+ assert ((int) ((int?) g) == int.MIN);
+ assert ((uint) ((uint?) t) == uint.MAX);
+}
+
void main () {
foo ((int64?) int64.MIN, (uint64?) uint64.MAX);
foo<int64?,uint64?> ((int64?) int64.MIN, (uint64?) uint64.MAX);
+ bar ((int?) int.MIN, (uint?) uint.MAX);
+ bar<int?,uint?> ((int?) int.MIN, (uint?) uint.MAX);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]