[vala] Support non-null cast for enum values
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] Support non-null cast for enum values
- Date: Mon, 25 Mar 2013 19:22:29 +0000 (UTC)
commit 3fd429ed575333bfcbc1ef88347421e10e136bd4
Author: Luca Bruno <luca bruno immobiliare it>
Date: Mon Mar 25 13:20:55 2013 +0100
Support non-null cast for enum values
Fixes bug 673879.
codegen/valaccodebasemodule.vala | 6 +++---
tests/Makefile.am | 1 +
tests/enums/bug673879.vala | 12 ++++++++++++
3 files changed, 16 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a8d9e8c..332c9ba 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -5072,9 +5072,9 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
}
var innercexpr = get_cvalue (expr.inner);
- if (expr.type_reference.data_type is Struct && !expr.type_reference.nullable &&
- expr.inner.value_type.data_type is Struct && expr.inner.value_type.nullable) {
- // nullable integer or float or boolean or struct cast to non-nullable
+ if (expr.type_reference is ValueType && !expr.type_reference.nullable &&
+ expr.inner.value_type is ValueType && expr.inner.value_type.nullable) {
+ // nullable integer or float or boolean or struct or enum cast to non-nullable
innercexpr = new CCodeUnaryExpression
(CCodeUnaryOperator.POINTER_INDIRECTION, innercexpr);
}
set_cvalue (expr, new CCodeCastExpression (innercexpr, get_ccode_name
(expr.type_reference)));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index c11565c..a647bb5 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -63,6 +63,7 @@ TESTS = \
control-flow/bug652549.vala \
control-flow/bug665904.vala \
enums/enums.vala \
+ enums/bug673879.vala \
structs/structs.vala \
structs/gvalue.vala \
structs/bug530605.vala \
diff --git a/tests/enums/bug673879.vala b/tests/enums/bug673879.vala
new file mode 100644
index 0000000..db32ff6
--- /dev/null
+++ b/tests/enums/bug673879.vala
@@ -0,0 +1,12 @@
+enum Test
+{
+ TEST = 10
+}
+
+void main()
+{
+ Test? test = null;
+
+ test = Test.TEST;
+ assert ((!)test == 10);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]