[vala/staging] Check for assignment to constant
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] Check for assignment to constant
- Date: Sun, 18 Sep 2016 19:27:36 +0000 (UTC)
commit 33879ec4c2286314957ac0e03a5a8e89ba6faa02
Author: Simon Werbeck <simon werbeck gmail com>
Date: Sun Sep 18 18:30:02 2016 +0200
Check for assignment to constant
This simply checks if the left-hand side is a constant and if so raises
an error.
Fixes bug 771626
tests/Makefile.am | 1 +
tests/basic-types/bug771626.test | 7 +++++++
vala/valaassignment.vala | 6 ++++++
3 files changed, 14 insertions(+), 0 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 0832a41..b2caa77 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -41,6 +41,7 @@ TESTS = \
basic-types/bug729907.vala \
basic-types/bug731017.vala \
basic-types/bug761307.vala \
+ basic-types/bug771626.test \
namespaces.vala \
methods/lambda.vala \
methods/closures.vala \
diff --git a/tests/basic-types/bug771626.test b/tests/basic-types/bug771626.test
new file mode 100644
index 0000000..64a5da8
--- /dev/null
+++ b/tests/basic-types/bug771626.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+const int FOO = 0;
+
+void main () {
+ FOO = 1;
+}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index a6b73b9..fc27acf 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -145,6 +145,12 @@ public class Vala.Assignment : Expression {
if (left is MemberAccess) {
var ma = (MemberAccess) left;
+ if (ma.symbol_reference is Constant) {
+ error = true;
+ Report.error (source_reference, "Assignment to constant after
initialization");
+ return false;
+ }
+
if ((!(ma.symbol_reference is Signal || ma.symbol_reference is DynamicProperty) &&
ma.value_type == null) ||
(ma.inner == null && ma.member_name == "this" &&
context.analyzer.is_in_instance_method ())) {
error = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]