diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-07-03 19:33:41 +0200 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-07-04 13:05:48 +0200 |
commit | 502686203c2f21067783eada6af6465ce0d3d318 (patch) | |
tree | 4b6aea891d306b62fe7446b76bdf1df72abc42e6 /tests/arrays | |
parent | 7d3b60848803ddbfe583ecc13f020fea0762f6c9 (diff) | |
download | vala-502686203c2f21067783eada6af6465ce0d3d318.tar.gz |
vala: Don't allow "resize" invocation on variable with unowned array type
Fixes https://gitlab.gnome.org/GNOME/vala/issues/928
Diffstat (limited to 'tests/arrays')
-rw-r--r-- | tests/arrays/resize-unowned-invalid-2.test | 10 | ||||
-rw-r--r-- | tests/arrays/resize-unowned-invalid-3.test | 9 | ||||
-rw-r--r-- | tests/arrays/resize-unowned-invalid.test | 7 | ||||
-rw-r--r-- | tests/arrays/resize.vala | 29 |
4 files changed, 55 insertions, 0 deletions
diff --git a/tests/arrays/resize-unowned-invalid-2.test b/tests/arrays/resize-unowned-invalid-2.test new file mode 100644 index 000000000..be1ab49ef --- /dev/null +++ b/tests/arrays/resize-unowned-invalid-2.test @@ -0,0 +1,10 @@ +Invalid Code + +void bar (string[] foo) { + foo.resize (42); +} + +void main () { + var foo = new string[23]; + bar (foo); +} diff --git a/tests/arrays/resize-unowned-invalid-3.test b/tests/arrays/resize-unowned-invalid-3.test new file mode 100644 index 000000000..b76d4b7c8 --- /dev/null +++ b/tests/arrays/resize-unowned-invalid-3.test @@ -0,0 +1,9 @@ +Invalid Code + +unowned string[] foo; + +void main () { + var bar = new string[23]; + foo = bar; + foo.resize (42); +} diff --git a/tests/arrays/resize-unowned-invalid.test b/tests/arrays/resize-unowned-invalid.test new file mode 100644 index 000000000..b9d7aea4d --- /dev/null +++ b/tests/arrays/resize-unowned-invalid.test @@ -0,0 +1,7 @@ +Invalid Code + +void main () { + var foo = new string[23]; + unowned string[] bar = foo; + bar.resize (42); +} diff --git a/tests/arrays/resize.vala b/tests/arrays/resize.vala new file mode 100644 index 000000000..0ed1bc1de --- /dev/null +++ b/tests/arrays/resize.vala @@ -0,0 +1,29 @@ +void bar (ref string[] foo) { + foo.resize (42); +} + +void manam (out string[] foo) { + foo = new string[23]; + foo.resize (42); +} + +string[] boo; + +void main () { + { + var foo = new string[23]; + foo.resize (42); + } + { + var foo = new string[23]; + bar (ref foo); + } + { + string[] foo; + manam (out foo); + } + { + boo = new string[23]; + boo.resize (42); + } +} |