[vala/staging] codegen: Drop inner casts before converting between generics and integers
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Drop inner casts before converting between generics and integers
- Date: Wed, 10 Mar 2021 11:15:37 +0000 (UTC)
commit f969ed96471f224a7bb8774ee23801ebe39ef1f8
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Mar 10 12:12:06 2021 +0100
codegen: Drop inner casts before converting between generics and integers
Found by -Wpointer-to-int-cast
codegen/valaccodebasemodule.vala | 16 ++++++++++++++++
tests/Makefile.am | 1 +
tests/generics/integer-member-access.vala | 18 ++++++++++++++++++
3 files changed, 35 insertions(+)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index ae6fddbf3..308aa034e 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -6003,8 +6003,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
generate_type_declaration (actual_type, cfile);
result = new CCodeCastExpression (cexpr, get_ccode_name (actual_type));
} else if (analyzer.is_signed_integer_type_argument (actual_type)) {
+ // FIXME this should not happen
+ while (cexpr is CCodeCastExpression) {
+ cexpr = ((CCodeCastExpression) cexpr).inner;
+ }
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "gintptr"),
get_ccode_name (actual_type));
} else if (analyzer.is_unsigned_integer_type_argument (actual_type)) {
+ // FIXME this should not happen
+ while (cexpr is CCodeCastExpression) {
+ cexpr = ((CCodeCastExpression) cexpr).inner;
+ }
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "guintptr"),
get_ccode_name (actual_type));
}
return result;
@@ -6014,8 +6022,16 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
unowned SemanticAnalyzer analyzer = context.analyzer;
var result = cexpr;
if (analyzer.is_signed_integer_type_argument (actual_type)) {
+ // FIXME this should not happen
+ while (cexpr is CCodeCastExpression) {
+ cexpr = ((CCodeCastExpression) cexpr).inner;
+ }
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "gintptr"),
get_ccode_name (pointer_type));
} else if (analyzer.is_unsigned_integer_type_argument (actual_type)) {
+ // FIXME this should not happen
+ while (cexpr is CCodeCastExpression) {
+ cexpr = ((CCodeCastExpression) cexpr).inner;
+ }
result = new CCodeCastExpression (new CCodeCastExpression (cexpr, "guintptr"),
get_ccode_name (pointer_type));
}
return result;
diff --git a/tests/Makefile.am b/tests/Makefile.am
index b22e19768..6e7bd28b8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -675,6 +675,7 @@ TESTS = \
generics/gvariant-serialization.test \
generics/inference-argument-may-fail.vala \
generics/inference-static-function.vala \
+ generics/integer-member-access.vala \
generics/integer-type-cast.vala \
generics/integer-type-cast-return.vala \
generics/parameter-invalid-initializer.test \
diff --git a/tests/generics/integer-member-access.vala b/tests/generics/integer-member-access.vala
new file mode 100644
index 000000000..47dc31a13
--- /dev/null
+++ b/tests/generics/integer-member-access.vala
@@ -0,0 +1,18 @@
+class Foo<K,V> {
+ public K k;
+ public V v;
+}
+
+void main () {
+ var foo = new Foo<int,uint> ();
+ foo.k = int.MIN;
+ foo.v = uint.MAX;
+ assert (foo.k == int.MIN);
+ assert (foo.v == uint.MAX);
+
+ var bar = new Foo<int,uint> ();
+ bar.k = foo.k;
+ bar.v = foo.v;
+ assert (bar.k == int.MIN);
+ assert (bar.v == uint.MAX);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]