[vala/staging] vala: Property must be writable when invoking ReturnsModifiedPointer method
- From: Rico Tzschichholz <ricotz src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala/staging] vala: Property must be writable when invoking ReturnsModifiedPointer method
- Date: Sat, 4 Jul 2020 12:18:27 +0000 (UTC)
commit 85cff726250620cf7326393285fbe4cbd4d22571
Author: Rico Tzschichholz <ricotz ubuntu com>
Date: Sat Jul 4 09:07:06 2020 +0200
vala: Property must be writable when invoking ReturnsModifiedPointer method
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1023
tests/Makefile.am | 1 +
tests/semantic/property-method-returns-modified-pointer.test | 10 ++++++++++
vala/valamethodcall.vala | 8 +++++++-
3 files changed, 18 insertions(+), 1 deletion(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index da440e248..b6f9574e8 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -911,6 +911,7 @@ TESTS = \
semantic/property-accessibility.test \
semantic/property-construct.test \
semantic/property-initializer-type.test \
+ semantic/property-method-returns-modified-pointer.test \
semantic/property-override.test \
semantic/property-override-class.test \
semantic/property-override-interface.test \
diff --git a/tests/semantic/property-method-returns-modified-pointer.test
b/tests/semantic/property-method-returns-modified-pointer.test
new file mode 100644
index 000000000..ae8ebbe6f
--- /dev/null
+++ b/tests/semantic/property-method-returns-modified-pointer.test
@@ -0,0 +1,10 @@
+Invalid Code
+
+class Foo {
+ public List<string> bar { get; }
+}
+
+void main () {
+ var foo = new Foo ();
+ foo.bar.append ("foo");
+}
diff --git a/vala/valamethodcall.vala b/vala/valamethodcall.vala
index baf704f45..2416e5b9f 100644
--- a/vala/valamethodcall.vala
+++ b/vala/valamethodcall.vala
@@ -527,7 +527,13 @@ public class Vala.MethodCall : Expression {
value_type.floating_reference = true;
}
if (m.returns_modified_pointer) {
- ((MemberAccess) call).inner.lvalue = true;
+ unowned Expression inner = ((MemberAccess) call).inner;
+ inner.lvalue = true;
+ unowned Property? prop = inner.symbol_reference as Property;
+ if (prop != null && (prop.set_accessor == null ||
!prop.set_accessor.writable)) {
+ error = true;
+ Report.error (inner.source_reference, "Property `%s' is
read-only".printf (prop.get_full_name ()));
+ }
}
// avoid passing possible null to ref_sink_function without checking
if (tree_can_fail && !value_type.nullable && value_type.floating_reference &&
ret_type is ObjectType) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]