[vala/0.48] codegen: Strip all nested occurances of CCodeCastExpression



commit 669681a927c82498abe90a0f9a82e6417ad07941
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Sun Feb 7 19:04:56 2021 +0100

    codegen: Strip all nested occurances of CCodeCastExpression
    
    Triggered by 63551acaf0d83fac8b50904c2759c1098fbfaa71
    
    See https://gitlab.gnome.org/GNOME/vala/issues/1134

 codegen/valaccodebasemodule.vala             |  5 +++--
 tests/Makefile.am                            |  1 +
 tests/generics/integer-type-cast-return.vala | 14 ++++++++++++++
 3 files changed, 18 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index d145f06d5..f4837193c 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -3697,9 +3697,10 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                        }
 
                        // FIXME this breaks in our macro, so this should not happen
-                       if (cvar is CCodeCastExpression) {
+                       while (cvar is CCodeCastExpression) {
                                cvar = ((CCodeCastExpression) cvar).inner;
-                       } else if (cvar is CCodeFunctionCall) {
+                       }
+                       if (cvar is CCodeFunctionCall) {
                                cvar = ((CCodeFunctionCall) cvar).get_arguments ()[0];
                        }
 
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e979286d9..20298a92c 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -645,6 +645,7 @@ TESTS = \
        generics/inference-argument-may-fail.vala \
        generics/inference-static-function.vala \
        generics/integer-type-cast.vala \
+       generics/integer-type-cast-return.vala \
        generics/parameter-invalid-initializer.test \
        generics/parameter-sizeof-initializer.vala \
        generics/member-dup-destroy.vala \
diff --git a/tests/generics/integer-type-cast-return.vala b/tests/generics/integer-type-cast-return.vala
new file mode 100644
index 000000000..b7c74d66e
--- /dev/null
+++ b/tests/generics/integer-type-cast-return.vala
@@ -0,0 +1,14 @@
+T manam <T> (int i) {
+       return (int?) i;
+}
+
+T minim <T> (uint i) {
+       return (uint?) i;
+}
+
+void main () {
+       assert (manam<int?> (int.MIN) == int.MIN);
+       assert (minim<uint?> (uint.MAX) == uint.MAX);
+       assert ((int) ((int?) manam<int?> (int.MIN)) == int.MIN);
+       assert ((uint) ((uint?) minim<uint?> (uint.MAX)) == uint.MAX);
+}


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