[vala/0.52] vala: Check for unavailable value-type of variable initializer
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/0.52] vala: Check for unavailable value-type of variable initializer
- Date: Thu, 18 Nov 2021 20:56:47 +0000 (UTC)
commit e8fd08b15889ce99f7cc8c032b770a246bd1b85d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Wed Nov 17 18:46:22 2021 +0100
vala: Check for unavailable value-type of variable initializer
Regression of 6690ea0e3c6f0d81d849e13548efc8c0809149cc
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1253
tests/Makefile.am | 2 ++
tests/semantic/assignment-invalid-type.test | 7 +++++++
tests/semantic/initializer-invalid-type.test | 5 +++++
vala/valaassignment.vala | 4 ++++
vala/valalocalvariable.vala | 4 ++++
5 files changed, 22 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 6a9070d58..1fb4e1d1a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -953,6 +953,7 @@ TESTS = \
semantic/assignment-same-variable.vala \
semantic/assignment-signal-incompatible-method.test \
semantic/assignment-signal-incompatible-type.test \
+ semantic/assignment-invalid-type.test \
semantic/cast-gvalue-unsupported.test \
semantic/cast-gvariant-unsupported.test \
semantic/cast-void-not-allowed.vala \
@@ -1044,6 +1045,7 @@ TESTS = \
semantic/foreach-next-value-void.test \
semantic/foreach-next-void.test \
semantic/foreach-wrong-types.test \
+ semantic/initializer-invalid-type.test \
semantic/initializer-unknown-type.test \
semantic/interface-prerequisite-invalid.test \
semantic/interface-prerequisite-less-accessible.test \
diff --git a/tests/semantic/assignment-invalid-type.test b/tests/semantic/assignment-invalid-type.test
new file mode 100644
index 000000000..261c52ed0
--- /dev/null
+++ b/tests/semantic/assignment-invalid-type.test
@@ -0,0 +1,7 @@
+Invalid Code
+
+string bar;
+
+void main () {
+ bar = string;
+}
diff --git a/tests/semantic/initializer-invalid-type.test b/tests/semantic/initializer-invalid-type.test
new file mode 100644
index 000000000..2f8e91eaf
--- /dev/null
+++ b/tests/semantic/initializer-invalid-type.test
@@ -0,0 +1,5 @@
+Invalid Code
+
+void main () {
+ string foo = string;
+}
diff --git a/vala/valaassignment.vala b/vala/valaassignment.vala
index 46f9445a4..137361b28 100644
--- a/vala/valaassignment.vala
+++ b/vala/valaassignment.vala
@@ -297,6 +297,10 @@ public class Vala.Assignment : Expression {
Report.error (source_reference, "Assignment: Invalid assignment
attempt");
return false;
}
+ } else if (ma.symbol_reference is Variable && right.value_type == null) {
+ error = true;
+ Report.error (source_reference, "Assignment: Invalid assignment attempt");
+ return false;
} else if (ma.symbol_reference is Variable) {
unowned Variable variable = (Variable) ma.symbol_reference;
unowned ArrayType? variable_array_type = variable.variable_type as ArrayType;
diff --git a/vala/valalocalvariable.vala b/vala/valalocalvariable.vala
index eeb8e912b..b4fe16ba4 100644
--- a/vala/valalocalvariable.vala
+++ b/vala/valalocalvariable.vala
@@ -205,6 +205,10 @@ public class Vala.LocalVariable : Variable {
Report.error (source_reference, "expression type not allowed as
initializer");
return false;
}
+ } else if (initializer.value_type == null) {
+ error = true;
+ Report.error (source_reference, "expression type not allowed as initializer");
+ return false;
}
if (!initializer.value_type.compatible (variable_type)) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]