[vala/staging] codegen: Use CCodeConstant for constants if possible
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] codegen: Use CCodeConstant for constants if possible
- Date: Thu, 16 Jul 2020 16:28:30 +0000 (UTC)
commit 3862aa97375a5b55b0541b3be02c8e0ec375a6b2
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Thu Jul 16 16:59:46 2020 +0200
codegen: Use CCodeConstant for constants if possible
This fixes an unexpected error when initializing static field with constant
codegen/valaccodememberaccessmodule.vala | 2 ++
tests/Makefile.am | 1 +
tests/constants/static-field-initializer.vala | 5 +++++
3 files changed, 8 insertions(+)
---
diff --git a/codegen/valaccodememberaccessmodule.vala b/codegen/valaccodememberaccessmodule.vala
index 1cec90ac6..4c24508ab 100644
--- a/codegen/valaccodememberaccessmodule.vala
+++ b/codegen/valaccodememberaccessmodule.vala
@@ -162,6 +162,8 @@ public abstract class Vala.CCodeMemberAccessModule : CCodeControlFlowModule {
s = current_method.get_full_name ();
}
set_cvalue (expr, new CCodeConstant ("\"%s\"".printf (s)));
+ } else if (is_constant_ccode (c)) {
+ set_cvalue (expr, new CCodeConstant (get_ccode_name (c)));
} else {
set_cvalue (expr, new CCodeIdentifier (get_ccode_name (c)));
}
diff --git a/tests/Makefile.am b/tests/Makefile.am
index d80ef2ed0..18f16f0f8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -77,6 +77,7 @@ TESTS = \
basic-types/bug788775.vala \
constants/array-type-invalid.test \
constants/glog.vala \
+ constants/static-field-initializer.vala \
namespace/unique.vala \
arrays/cast-silent-invalid.test \
arrays/class-field-length-cname.vala \
diff --git a/tests/constants/static-field-initializer.vala b/tests/constants/static-field-initializer.vala
new file mode 100644
index 000000000..d0c1c8df6
--- /dev/null
+++ b/tests/constants/static-field-initializer.vala
@@ -0,0 +1,5 @@
+int foo = int.MAX;
+
+void main () {
+ assert (foo == int.MAX);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]