From: Rico Tzschichholz Date: Sun, 7 Feb 2021 18:04:56 +0000 (+0100) Subject: codegen: Strip all nested occurances of CCodeCastExpression X-Git-Tag: 0.50.4~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e4d38adf885e5bc5760b7ec03fab5ce99b06bd12;p=thirdparty%2Fvala.git codegen: Strip all nested occurances of CCodeCastExpression Triggered by 63551acaf0d83fac8b50904c2759c1098fbfaa71 See https://gitlab.gnome.org/GNOME/vala/issues/1134 --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index 171c6f0fb..c434ac1be 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3724,9 +3724,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 d162ef2fc..1655968e7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -654,6 +654,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 (int i) { + return (int?) i; +} + +T minim (uint i) { + return (uint?) i; +} + +void main () { + assert (manam (int.MIN) == int.MIN); + assert (minim (uint.MAX) == uint.MAX); + assert ((int) ((int?) manam (int.MIN)) == int.MIN); + assert ((uint) ((uint?) minim (uint.MAX)) == uint.MAX); +}