summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeremy Philippe <jeremy.philippe@gmail.com>2020-01-07 22:05:57 +0100
committerRico Tzschichholz <ricotz@ubuntu.com>2020-01-08 15:01:21 +0100
commit7850210bafcdd81f5b7a36b82766ae73f0fa0610 (patch)
tree433ac354f51153d122dc3af151793cfd83502d4d /tests
parentce690e98c96aa610408bf23512acf93ec38990ee (diff)
downloadvala-7850210bafcdd81f5b7a36b82766ae73f0fa0610.tar.gz
vala: Infer target_type in coalescing expressions
Correctly handle reference tranfers of inner expressions. Fixes https://gitlab.gnome.org/GNOME/vala/issues/892
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rw-r--r--tests/control-flow/coalesce-reference-transfer.vala23
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a486591ec..2c66135bf 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -165,6 +165,7 @@ TESTS = \
control-flow/assigned-local-variable.vala \
control-flow/break.vala \
control-flow/break-invalid.test \
+ control-flow/coalesce-reference-transfer.vala \
control-flow/continue-invalid.test \
control-flow/double-catch.test \
control-flow/expressions-conditional.vala \
diff --git a/tests/control-flow/coalesce-reference-transfer.vala b/tests/control-flow/coalesce-reference-transfer.vala
new file mode 100644
index 000000000..4efbf3ed4
--- /dev/null
+++ b/tests/control-flow/coalesce-reference-transfer.vala
@@ -0,0 +1,23 @@
+[Compact]
+class Foo {
+ public int i;
+
+ public Foo (int i) {
+ this.i = i;
+ }
+}
+
+Foo? get_foo (int? i) {
+ return i != null ? new Foo (i) : null;
+}
+
+void main () {
+ {
+ Foo foo = get_foo (null) ?? get_foo (42);
+ assert (foo.i == 42);
+ }
+ {
+ Foo foo = get_foo (null) ?? (get_foo (null) ?? get_foo (42));
+ assert (foo.i == 42);
+ }
+}